Added error handling
This commit is contained in:
parent
37ed65e0b7
commit
8960b29128
|
@ -27,6 +27,7 @@ pub mod rejection {
|
|||
use async_graphql::ParseRequestError;
|
||||
use axum::body::Body;
|
||||
use axum::response::IntoResponse;
|
||||
use http::StatusCode;
|
||||
|
||||
/// Rejection used for [`GraphQLRequest`](GraphQLRequest).
|
||||
pub struct GraphQLRejection(pub ParseRequestError);
|
||||
|
@ -36,7 +37,16 @@ pub mod rejection {
|
|||
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
|
||||
|
||||
fn into_response(self) -> http::Response<Body> {
|
||||
todo!()
|
||||
match self.0 {
|
||||
ParseRequestError::PayloadTooLarge => http::Response::builder()
|
||||
.status(StatusCode::PAYLOAD_TOO_LARGE)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
bad_request => http::Response::builder()
|
||||
.status(StatusCode::BAD_REQUEST)
|
||||
.body(Body::from(format!("{:?}", bad_request)))
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user