Closed dpc closed 2 years ago
pub async fn verify_jsonrpc_response(resp: GooseResponse) -> Result<(), TransactionError> {
let jsonrpc_resp: JsonRpcResponse = resp.response?.json().await?;
if let Some(_error) = &jsonrpc_resp.error {
return Err(TransactionError::RequestFailed {
raw_request: resp.request,
});
}
if jsonrpc_resp.result.is_none() {
return Err(TransactionError::RequestFailed {
raw_request: resp.request,
});
}
Ok(())
}
This is what I'm using right now. It does work and shows up the Transaction as failed in the stats, but it is completely loosing any nuance like the error message.
I've considered converting Goose to using thiserror
instead of using custom error types. But, it would also be easy to just add a custom error type.
thiserror
is really handy and popular, I use it anytime I want non-boxed errors.
Though in this issue I guess it's a matter of a concept and how it fits with other parts. I have a very custom tool to build, so I expect to have to conform to some pre-existing frame. I guess what might make sense is to have a ValidationFailed
or something - for all these cases where someone (like me) has to do content-specific validation.
https://book.goose.rs/getting-started/validation.html Seemed to be kind of in this area, but not exactly (I had to just write some custom code), and it didn't seem to present any "validation error".
Related request: https://github.com/tag1consulting/goose/issues/250
Closing as a DUP then. #250 looks like what I want as well.
In JsonRPC the logical error is inside the body of the response. I can write the code to validate it, but I can't really see a good variant to use for the request failure. Ideally I would be able to pout the error message inside and get it reported like other errors of this type.