File tree 1 file changed +18
-0
lines changed
utils/scarb-proc-macro-server-types/src
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,24 @@ pub struct RpcResponse {
18
18
pub error : Option < ResponseError > ,
19
19
}
20
20
21
+ impl RpcResponse {
22
+ /// Converts this response into a [`Result`], containing either the successful result
23
+ /// or the error that occurred during the RPC request.
24
+ ///
25
+ /// # Returns
26
+ /// * `Ok(serde_json::Value)` if the RPC request was successful and contains a result.
27
+ /// * `Err(ResponseError)` if the RPC request failed and contains an error.
28
+ pub fn into_result ( self ) -> Result < serde_json:: Value , ResponseError > {
29
+ match ( self . result , self . error ) {
30
+ ( _, Some ( error) ) => Err ( error) ,
31
+ ( Some ( response) , None ) => Ok ( response) ,
32
+ ( None , None ) => Err ( ResponseError {
33
+ message : "`RpcResponse` is missing both `result` and `error`." . to_string ( ) ,
34
+ } ) ,
35
+ }
36
+ }
37
+ }
38
+
21
39
/// Describes errors that occurred during an RPC operation.
22
40
///
23
41
/// Provides an error message detailing what went wrong during the request.
You can’t perform that action at this time.
0 commit comments