Skip to content

Commit a76811a

Browse files
committed
feat: Print validation results even when --errors flag is passed
1 parent d7b6ce3 commit a76811a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

docs/guides/06-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ curl http://localhost:4010/todos -H "accept: application/json"`
194194
195195
**Returned Status Code: `500`**
196196
197-
**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.
197+
**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.
198198
199199
**Message #2: response.body Request body must match exactly one schema in oneOf**
200200

packages/http-server/src/server.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,12 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe
121121

122122
if (inputOutputValidationErrors.length > 0) {
123123
addViolationHeader(reply, inputOutputValidationErrors);
124-
125-
const errorViolations = outputValidationErrors.filter(
126-
v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error]
127-
);
128-
129-
if (opts.config.errors && errorViolations.length > 0) {
130-
return IOE.left(
131-
ProblemJsonError.fromTemplate(
132-
VIOLATIONS,
133-
'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.',
134-
{ validation: errorViolations }
135-
)
136-
);
137-
}
138124
}
139125

126+
const errorViolations = outputValidationErrors.filter(
127+
v => v.severity === DiagnosticSeverity[DiagnosticSeverity.Error]
128+
);
129+
140130
inputOutputValidationErrors.forEach(validation => {
141131
const message = `Violation: ${validation.location.join('.') || ''} ${validation.message}`;
142132
if (validation.severity === DiagnosticSeverity[DiagnosticSeverity.Error]) {
@@ -148,6 +138,16 @@ export const createServer = (operations: IHttpOperation[], opts: IPrismHttpServe
148138
}
149139
});
150140

141+
if (opts.config.errors && errorViolations.length > 0) {
142+
return IOE.left(
143+
ProblemJsonError.fromTemplate(
144+
VIOLATIONS,
145+
'Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.',
146+
{ validation: errorViolations }
147+
)
148+
);
149+
}
150+
151151
return IOE.fromEither(
152152
E.tryCatch(() => {
153153
if (output.headers) Object.entries(output.headers).forEach(([name, value]) => reply.setHeader(name, value));

0 commit comments

Comments
 (0)