Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Request: throw 400 error on invalid response #53

Open
shahtr opened this issue Nov 6, 2019 · 0 comments
Open

Request: throw 400 error on invalid response #53

shahtr opened this issue Nov 6, 2019 · 0 comments

Comments

@shahtr
Copy link

shahtr commented Nov 6, 2019

Need validateResponse to throw an error for invalid responses, if no responseValidationFn is passed.

            res.set('Content-Type', ''); // Reset content-type since it is no longer valid
          }
          err.failedValidation = true;
          err.message = 'Value expected to be an array/object but is not';
          if (options.responseValidationFn) {
            options.responseValidationFn(req, data, [err]);
            sendData(res, data, encoding);
            return;
          }
          const resultError = {
            message: `Response schema validation failed for ${req.method}${req.originalUrl}`,
          };
          if (options.returnResponseErrors) {
            err.errors = [{ message: 'Invalid response format' }];
          }
          next(resultError);
          return;```

Need this to behave like validateRequest, where if there's no `options.requestValidationFn` and the request is invalid, the method sends 400 status with the error.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant