How to handle error from middleware #2750
Unanswered
SardineFish
asked this question in
Q&A
Replies: 1 comment 2 replies
-
|
In general you don't. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
In the middleware service chain, we call next service with
ServiceRequestand return theServiceResponsefrom the next service.But if next service return an error, how can we make it into a
ServiceResponseBackground
In our project, we need to make our APIs always response in a certain JSON format.
But if we have error in middleware, we can only return it out and let actix-web response an
Internal Serivce Error.We cannot make a custom
ServiceResponsebecauseServiceRequestis moved to next service and the innerHttpRequestcannot clone.For example in official middleware
ErrorHandlerline 157actix-web/actix-web/src/middleware/err_handlers.rs
Lines 148 to 177 in 6a5b370
The error from next service is just returned to upper service.
Finally it will become a
500response with default text bodyInternal Serivce Error.Beta Was this translation helpful? Give feedback.
All reactions