-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No easy way to create error without CallError #1115
Comments
I ended up with this helper: https://github.com/AcalaNetwork/subway/blob/2fc9a52f0404796d763f533ab802f3fea89fb35f/src/helper.rs those should be provided by jsonrpsee |
The reason is that the old jsonrpsee CallError did too much magic (convert it back and forth from a jsonrpsee::Error) and we decided it's better to require folks explicitly decide what to return. Because now it's possible to return custom error types that implements Sure, I agree that we can expose |
I am fine with refactoring, just don't take away features. I don't want to manually construct ErrorObejct. |
In case it's helpful to others making the upgrade to use jsonrpsee::types::error::ErrorObjectOwned as JsonRpcErrorOwned;
use jsonrpsee::types::error::SERVER_ERROR_MSG;
// Conversions for errors which occur in the context of a JSON-RPC method call.
// Crate-local error variants are converted to JSON-RPC errors which are
// then return to the caller.
impl From<Error> for JsonRpcErrorOwned {
fn from(err: Error) -> Self {
match &err {
Error::SerdeJson(err_msg) => {
JsonRpcErrorOwned::owned(-32000, SERVER_ERROR_MSG, Some(err_msg.to_string()))
}
Error::UrlParse(err_msg) => {
JsonRpcErrorOwned::owned(-32001, SERVER_ERROR_MSG, Some(err_msg.to_string()))
}
Error::Validation(err_msg) => {
JsonRpcErrorOwned::owned(-32002, SERVER_ERROR_MSG, Some(err_msg.to_string()))
}
_ => todo!(),
}
}
} |
I am upgrading jsonrpsee and without CallError I just need to write lot more code to do the same.
For example, what's the best way for me to upgrade this code without writing extra helpers? I am expecting jsonrpsee providing helpers to generate standard error objects
https://github.com/AcalaNetwork/subway/blob/a6bbc19c3db67e21edde0fdf2837804928a81d22/src/middleware/inject_params.rs#L106-L113
The text was updated successfully, but these errors were encountered: