Skip to content

Commit

Permalink
changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrola committed Jun 1, 2023
1 parent 09a9bf6 commit b84b0df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-hotels-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ts-rest/express': minor
---

Add middleware directly through ts-rest with type-safe injected route object
5 changes: 5 additions & 0 deletions .changeset/tricky-dingos-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ts-rest/core': minor
---

Add 'metadata' property to routes
8 changes: 4 additions & 4 deletions libs/ts-rest/express/src/lib/ts-rest-express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ const initializeExpressRoute = ({
};

const requestValidationErrorHandler = (
requestValidationErrorHandler: TsRestExpressOptions<any>['requestValidationErrorHandler'] = 'default'
handler: TsRestExpressOptions<any>['requestValidationErrorHandler'] = 'default'
) => {
return (err: any, req: Request, res: Response, next: NextFunction) => {
if (err instanceof RequestValidationError) {
// old-style error handling, kept for backwards compatibility
if (requestValidationErrorHandler === 'default') {
if (handler === 'default') {
if (err.pathParams) {
return res.status(400).json(err.pathParams);
}
Expand All @@ -231,15 +231,15 @@ const requestValidationErrorHandler = (
if (err.body) {
return res.status(400).json(err.body);
}
} else if (requestValidationErrorHandler === 'combined') {
} else if (handler === 'combined') {
return res.status(400).json({
pathParameterErrors: err.pathParams,
headerErrors: err.headers,
queryParameterErrors: err.query,
bodyErrors: err.body,
});
} else {
return requestValidationErrorHandler(err, req as any, res, next);
return handler(err, req as any, res, next);
}
}

Expand Down

0 comments on commit b84b0df

Please sign in to comment.