-
Notifications
You must be signed in to change notification settings - Fork 3
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
Extend-errors #15
Extend-errors #15
Conversation
Note on usage/updating to the new error types SDK users will need to update their error conversion code. When converting from your own error types, you are encouraged to implement Error types have utility creation function that are generic over a reference to anything implementing QueryError::new_invalid_request(&"some static error string");
QueryError::new_unsupported_operation(&SomeErrorType); Additionally, each error type has an That error type is created with the
All error types are initially created without details. Users wishing to add details to a created error should use the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @BenoitRanque I think stepping through with you yesterday cleared everything up for me.
crates/sdk/src/connector.rs
Outdated
match self { | ||
Self::InvalidRequest(err) => (StatusCode::BAD_REQUEST, Json(err)), | ||
Self::UnprocessableContent(err) => (StatusCode::UNPROCESSABLE_ENTITY, Json(err)), | ||
Self::UnsupportedOperation(err) => (StatusCode::NOT_IMPLEMENTED, Json(err)), | ||
Self::Conflict(err) => (StatusCode::CONFLICT, Json(err)), | ||
Self::ConstraintNotMet(err) => (StatusCode::FORBIDDEN, Json(err)), | ||
Self::Other(err, details) => ( | ||
StatusCode::INTERNAL_SERVER_ERROR, | ||
Json(models::ErrorResponse { | ||
message: err.to_string(), | ||
details, | ||
}), | ||
), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
### What We want to update ndc-sdk-rs to 0.2.1, and it introduces several changes: 1. Error messages hasura/ndc-sdk-rs#15 2. Update ndc-spec to 0.1.5, which introduces breaking changes by adding newtype wrappers around string types ### How 1. For errors, follow hasura/ndc-sdk-rs#15 (comment) 2. For newtypes, go into type hell and fix the bugs by trying to put the ndc-models newtypes in the data structures, as they are more descriptive.
This PR extends errors to allow users of the SDK to set the details json object.
The PR also implements
IntoResponse
for all the error types, so they can be returned directly from their respective routes.This means the routes.rs file is removed. Note we add a
fetch_metrics
function, this contains the logic that used to live in the respective route (this was the only route with logic).Before merging, I'll move all the error types into their own file, but wanted to keep them as-is for now, so it's easier to see what changed/stayed the same.
You may notice the
IntoResponse
implementation does not use theto_string
method on the error types to add the prefix to the message. This is intentional, that information is conveyed with the status code.