swagger-express-middleware icon indicating copy to clipboard operation
swagger-express-middleware copied to clipboard

Provide granular error output customization

Open cdimascio opened this issue 8 years ago • 1 comments

currently, we have two properties on error, error.status and error.message. I'd like to propose that additional properties be added, so that the error messages can be better customized.

if the error object passed to the error handler function had a more granular structure, users could provide nicer error message.

For example, today the error.message for validation error will output something like this:

message The "body" body parameter is invalid ({"name":"june","location":{},"group":"","district":""})
JSON Schema validation error.
Data path: "/location"
Schema path: "/properties/location/required/0"
Missing required property: geo

It's quite verbose

I'd like to customize it to instead say something more succinct e.g.

Missing required property: /location/geo

Adding additional properties and/or changing the message makes this possible

{
  "type": "validation error",
  "message": "missing required fields",
  "property": "/location/geo"
}

and for a constraint mismatch

{
  "type": "validation error",
  "message": "expected object, got string",
  "property": "address",
}

etc...

The above structure (and messaging) needs a bit more thought, but you see where im gong

cdimascio avatar Feb 15 '17 02:02 cdimascio

@cdimascio Any resolution on this issue?

NigelEarle avatar Feb 05 '18 19:02 NigelEarle