Skip to content

Commit

Permalink
Add request validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
grafikrobot committed Oct 28, 2021
1 parent 0d754dc commit ec4d15c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/website/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ const corum_api = new OpenAPIBackend({ definition: corum_api_path });
corum_api.register({
notFound: corum_not_found,
postResponseHandler: corum_validate_response,
validationFail: corum_validation_fail,
meta: corum_meta,
get_product_min_by_id: corum_product_min_by_id,
get_product_full_by_id: corum_product_full_by_id,
Expand All @@ -339,6 +340,11 @@ async function corum_validate_response(context: OpenAPIContext, req: Request, re
}
}

async function corum_validation_fail(context: OpenAPIContext, req: Request, res: Response) {
var errors = context.validation.errors?.map(error => error.message);
return send_error(res, 400, "Failed validation: " + errors?.join(", ") + ".");
}

async function corum_not_found(context: OpenAPIContext, req: Request, res: Response) {
return send_404(res);
}
Expand Down

0 comments on commit ec4d15c

Please sign in to comment.