-
How can we return an error in middleware? I'm using middleware for validation and I'd like to return an error message whenever validation fails and makes the operation exit early. I'm currently just throwing an error when that happens, but I'm not sure if that's the proper way to do it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Throwing an exception is the correct way if you have an error. The early interruption of a middleware is to make everything go well without actually making the call on the db. Suppose we want to make a caching middleware, this can work by returning the result of the find in the before function. |
Beta Was this translation helpful? Give feedback.
Throwing an exception is the correct way if you have an error. The early interruption of a middleware is to make everything go well without actually making the call on the db. Suppose we want to make a caching middleware, this can work by returning the result of the find in the before function.