Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/06-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
28 changes: 14 additions & 14 deletions packages/http-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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));
Expand Down