Skip to content

Commit 0fe7bc5

Browse files
committed
Print validation results even when --errors flag is passed
1 parent 197eb6f commit 0fe7bc5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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)