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 just noticed that when parsing the incoming request fails, a plain 500 error will be returned, but not the ZodError.
In order for consumers to understand what wen wrong with the request, I suggest to return the ZodError in the response body. I also would probably choose a different error code, e.g. 400, to let the consumer know that they did something wrong.
Here's how I solved it for myself:
// ... inside the try catch}catch(error){throwcreateError(// use @middy/utils instead of http-errors400,// return 400 error code instead of 500JSON.stringify({// return the ZodError for the consumer so that they can understand what went wrongmissingParameters: JSON.parse((errorasany).message),// respond with error.message to return ZodError}),// in case other errors occur, add to error stack{cause: (errorasany).message,});}// ...
Please note that I use @middy/http-error-handler in my setup which is why I stringify the response body.
Maybe an option could be added to specify the error code and whether the ZodError should be returned?
The text was updated successfully, but these errors were encountered:
Hey,
I just noticed that when parsing the incoming request fails, a plain
500
error will be returned, but not theZodError
.In order for consumers to understand what wen wrong with the request, I suggest to return the
ZodError
in the response body. I also would probably choose a different error code, e.g.400
, to let the consumer know that they did something wrong.Here's how I solved it for myself:
Please note that I use
@middy/http-error-handler
in my setup which is why I stringify the response body.Maybe an option could be added to specify the error code and whether the
ZodError
should be returned?The text was updated successfully, but these errors were encountered: