restify / restify/node-restify
Restify does not handle Promise rejection
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
I'm trying to handle promise rejection creating a simple middleware, so I did:
const errorHandler = (err: Error, req: Request, res: Response, next: Next) => {
console.log('hello world');
}
so:
restify.use(errorHandler);
but surprising I get:
Argument of type '(err: Error, req: Request, res: Response, next: any) => void' is not assignable to parameter of type 'RequestHandlerType'.
Type '(err: Error, req: Request, res: Response, next: any) => void' is not assignable to type 'RequestHandler'.ts(2345)
so Restify does not include Error, and for manage the Promise rejection I should wrap this around each route:
export const errorHandler = (callback: Function) => {
return async function errorHandler(req: Request, res: Response, next: Next) {
try {
await callback(req, res, next)
} catch (err) {
next(err);
}
}
}
server.get('/access-codes/plan/:planId', errorHandler(list));
this could become a pain, why Restify doesn't support Error in RequestHandler?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the RequestHandlerType definition used by restify.use and trace how errors from middleware and server.get handlers are dispatched. Reproduce the reported Promise rejection and compare it with the errorHandler signature shown; done means the supported behavior and expected handler contract are established, with a focused regression check if the project has one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100