swagger-express-middleware
swagger-express-middleware copied to clipboard
Getting just validation errors messages - without whole error stack messages
How can I respond with proper JSON containing validator errors?
I'm using parseRequest middleware, the error I'm catching has proper status property for validation errors (400), but when I'm about to inform API consumer what exactly went wrong I have only the error message string with concatenated all errors messages in stack:
The \"newFloorPlan\" body parameter is invalid ({\"name\":\"string\",\"number\":0,\"width\":12,\"height\":12,\"backgroundImage\":\"string\",\"backgroundScale\":0,\"backgroundLocalNorthCoordinate\":123323,\"backgroundLocalEastCoordinate\":12})
JSON Schema validation error.
Data path: \"/backgroundLocalNorthCoordinate\"
Schema path: \"/properties/backgroundLocalNorthCoordinate/maximum\"
Value 123323 is greater than maximum 32767
I don't want to expose all the details to API consumer, I just need to expose input data errors, f.e:
[
{property: "backgroundLocalNorthCoordinate", message: "Value 123323 is greater than maximum 32767"
]
Is it possible?
+1