swagger-node-runner: Various error handling issues
Hi there, I’m having a hard time with error handling. When a validation error is raised it comes back as an ugly JSON response with my request buffer attached. How do developers opt out, or modify this error object?
I am using a project generated with swagger project create, with express.
The other thing, is that the swagger error responses are coming back clipped. Example:
{"message":"Response validation failed: failed schema validation","code":"SCHE
This may be related to #30
Am I please able to have some help in resolving these issues?
Many thanks, Wilfred
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 18
Is that request or response validation that you’re having issues with?
If it’s request validation, you can write your own error handling
fitting(which is very much like an express middleware) to handle validation errors and customise what’s sent to the client. I aStep 1
you’ll need to update your swagger configuration in
{project_root}/config/default.yamlto override the default json_error_handler with your own. For example, change:To
Step 2
Create fitting
errorFittingby creating{project_root}/api/fittings/errorFitting.js. To start with, you can just copy the existing json_error_handler into this and then customise it. You can detect if there was a validation error by looking at the error message like the tests does.By the way, I saw that you were using raw res.send etc. from your code. I think you could do a lot better by abstracting that away and use something like http-errors to simplify controller code and take advantage of middleware chaining via
nextin express, which is also honoured byswagger-node-runner. For example, here’s how a controller function in our codebase looks like: