Added error handling
This commit is contained in:
parent
2413c4158b
commit
908bbaf753
@ -27,6 +27,7 @@ pub mod rejection {
|
|||||||
use async_graphql::ParseRequestError;
|
use async_graphql::ParseRequestError;
|
||||||
use axum::body::Body;
|
use axum::body::Body;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
use http::StatusCode;
|
||||||
|
|
||||||
/// Rejection used for [`GraphQLRequest`](GraphQLRequest).
|
/// Rejection used for [`GraphQLRequest`](GraphQLRequest).
|
||||||
pub struct GraphQLRejection(pub ParseRequestError);
|
pub struct GraphQLRejection(pub ParseRequestError);
|
||||||
@ -36,7 +37,16 @@ pub mod rejection {
|
|||||||
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
|
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
|
||||||
|
|
||||||
fn into_response(self) -> http::Response<Body> {
|
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