throw on failure correctly
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
@@ -44,11 +44,12 @@ export class Proxy {
|
||||
this.requestResponsePairs.set(request, response);
|
||||
}
|
||||
delete this.#openRequests[response.id];
|
||||
try {
|
||||
this.validator.validate(request, response);
|
||||
} catch (err) {
|
||||
this.validator.validate(request, response).catch(err => {
|
||||
if (process.env.THROW) {
|
||||
throw err;
|
||||
}
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -522,7 +522,7 @@ export class OpenApiProxyValidator {
|
||||
];
|
||||
}
|
||||
|
||||
validate(request: CompletedRequest, response: CompletedResponse) {
|
||||
async validate(request: CompletedRequest, response: CompletedResponse) {
|
||||
const operation = this.findOperation(request);
|
||||
if (!operation) {
|
||||
throw RequestErrorFactory.createRequestError(
|
||||
@@ -534,13 +534,15 @@ export class OpenApiProxyValidator {
|
||||
const [path, operationSchema] = operation;
|
||||
|
||||
const validators = this.validators!;
|
||||
for (const validator of validators) {
|
||||
validator.validate({
|
||||
pair: { request, response },
|
||||
operationSchema,
|
||||
path,
|
||||
});
|
||||
}
|
||||
await Promise.all(
|
||||
validators.map(validator =>
|
||||
validator.validate({
|
||||
pair: { request, response },
|
||||
operationSchema,
|
||||
path,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private findOperation(
|
||||
|
||||
Reference in New Issue
Block a user