turkerdev / fastify-type-provider-zod

MIT License
337 stars 21 forks source link

Validation error returns 500's due to response schema #27

Open eddie-englund opened 1 year ago

eddie-englund commented 1 year ago

Hey!

I was just wondering how I'm supposed to add the response schema that for example a zod object can return when validation fails.

Currently, if validation fails all I get is this:

{
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "Response doesn't match the schema"
}
eddie-englund commented 1 year ago

Although I notice that if I don't supply a 500 and 400 in the response schema I guess something like this:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "[\n  {\n    \"code\": \"invalid_type\",\n    \"expected\": \"string\",\n    \"received\": \"undefined\",\n    \"path\": [\n      \"adminUsername\"\n    ],\n    \"message\": \"Required\"\n  }\n]"
}

But this would force the client to parse the "message" property to json. Would it be possible to have this as actual json instead? Also this makes it so that I can't type my response in case of errors where want to return 400, 401, 500, etc.

Lzok commented 1 year ago

@eddie-englund Hello! How are you? I think this is a duplicate of https://github.com/turkerdev/fastify-type-provider-zod/issues/26