diff --git a/docs/guides/06-errors.md b/docs/guides/06-errors.md index 50c4660fb..465bb88e4 100644 --- a/docs/guides/06-errors.md +++ b/docs/guides/06-errors.md @@ -194,7 +194,7 @@ curl http://localhost:4010/todos -H "accept: application/json"` **Returned Status Code: `500`** -**Explanation:** This error occurs when you're run Prism with the `--errors` flag and the request or the response has at least one violation marked as an error. +**Explanation:** This error occurs when you've run Prism with the `--errors` flag and the request or the response has at least one violation marked as an error. **Message #2: response.body Request body must match exactly one schema in oneOf** diff --git a/packages/http-server/src/server.ts b/packages/http-server/src/server.ts index 9aeda423e..e7ee8c91d 100644 --- a/packages/http-server/src/server.ts +++ b/packages/http-server/src/server.ts @@ -121,22 +121,12 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe if (inputOutputValidationErrors.length > 0) { addViolationHeader(reply, inputOutputValidationErrors); - - const errorViolations = outputValidationErrors.filter( - v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error] - ); - - if (opts.config.errors && errorViolations.length > 0) { - return IOE.left( - ProblemJsonError.fromTemplate( - VIOLATIONS, - 'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.', - { validation: errorViolations } - ) - ); - } } + const errorViolations = outputValidationErrors.filter( + v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error] + ); + inputOutputValidationErrors.forEach(validation => { const message = `Violation: ${validation.location.join('.') || ''} ${validation.message}`; if (validation.severity === DiagnosticSeverity[DiagnosticSeverity.Error]) { @@ -148,6 +138,16 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe } }); + if (opts.config.errors && errorViolations.length > 0) { + return IOE.left( + ProblemJsonError.fromTemplate( + VIOLATIONS, + 'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.', + { validation: errorViolations } + ) + ); + } + return IOE.fromEither( E.tryCatch(() => { if (output.headers) Object.entries(output.headers).forEach(([name, value]) => reply.setHeader(name, value));