Skip to content

Commit

Permalink
Handle bad URI (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
benblack86 authored Apr 3, 2021
1 parent 07ca93a commit 42baee3
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/middlewares/openapi.metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { pathToRegexp } from 'path-to-regexp';
import { Response, NextFunction } from 'express';
import { OpenApiContext } from '../framework/openapi.context';
import {
BadRequest,
MethodNotAllowed,
NotFound,
OpenApiRequest,
Expand Down Expand Up @@ -81,17 +82,24 @@ export function applyOpenApiMetadata(

if (matchedRoute) {
const paramKeys = keys.map((k) => k.name);
const paramsVals = matchedRoute.slice(1).map(decodeURIComponent);
const pathParams = _zipObject(paramKeys, paramsVals);
try {
const paramsVals = matchedRoute.slice(1).map(decodeURIComponent);
const pathParams = _zipObject(paramKeys, paramsVals);

const r = {
schema,
expressRoute,
openApiRoute,
pathParams,
};
(<any>r)._responseSchema = _schema;
return r;
const r = {
schema,
expressRoute,
openApiRoute,
pathParams,
};
(<any>r)._responseSchema = _schema;
return r;
} catch (error) {
throw new BadRequest({
path: req.path,
message: 'invalid URI',
})
}
}
}

Expand Down

0 comments on commit 42baee3

Please sign in to comment.