You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know I can change the return type of my function to customize error in my handling logic, but what if I'd like to decorate the error message when fail to <Json<Query> as poem::FromRequest>::from_request(&req, &mut body).await??.
Code example (if possible)
By default, it may return:
HTTP/1.1 400 Bad Request
Content-Length: 77
Connection: keep-alive
Date: Sun, 12 May 2024 06:30:37 GMT
Keep-Alive: timeout=4
Proxy-Connection: keep-alive
parse error: invalid type: integer `1`, expected a string at line 1 column 12
while I'd prefer to customize the error message, like:
HTTP/1.1 400 Bad Request
Content-Length: 77
Connection: keep-alive
Date: Sun, 12 May 2024 06:30:37 GMT
Keep-Alive: timeout=4
Proxy-Connection: keep-alive
0: fail to parse JSON payoad, at src/lib.rs:4:10
1: parse error: invalid type: integer `1`, expected a string at line 1 column 12
The text was updated successfully, but these errors were encountered:
By default, the extractor will return a 400 Bad Request when an error occurs, but sometimes you may want to change this behavior, so you can handle the error yourself.
In the following example, when the Query extractor fails, it will return a 500 Internal Server response and the reason for the error.
Seems like we can use a Result<[Extractor]> extractor?
Description of the feature
This code snippet:
would be expanded to:
I know I can change the return type of my function to customize error in my handling logic, but what if I'd like to decorate the error message when fail to
<Json<Query> as poem::FromRequest>::from_request(&req, &mut body).await?
?.Code example (if possible)
By default, it may return:
while I'd prefer to customize the error message, like:
The text was updated successfully, but these errors were encountered: