MCPcopy Create free account
hub / github.com/actix/examples / json_error_handler

Function json_error_handler

json/json-decode-error/src/main.rs:14–26  ·  view source on GitHub ↗
(err: error::JsonPayloadError, _req: &HttpRequest)

Source from the content-addressed store, hash-verified

12}
13
14fn json_error_handler(err: error::JsonPayloadError, _req: &HttpRequest) -> error::Error {
15 use actix_web::error::JsonPayloadError;
16
17 let detail = err.to_string();
18 let resp = match &err {
19 JsonPayloadError::ContentType => HttpResponse::UnsupportedMediaType().body(detail),
20 JsonPayloadError::Deserialize(json_err) if json_err.is_data() => {
21 HttpResponse::UnprocessableEntity().body(detail)
22 }
23 _ => HttpResponse::BadRequest().body(detail),
24 };
25 error::InternalError::from_response(err, resp).into()
26}
27
28#[actix_web::main]
29async fn main() -> std::io::Result<()> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected