Added error handling

This commit is contained in:
chris 2021-09-09 19:23:16 -07:00
parent 37ed65e0b7
commit 8960b29128

View File

@ -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(),
}
}
}