Error: next() called multiple times
See original GitHub issueHello,
when defined multiple http status codes in output
error is thrown.
- when only “400-599” is defined then ot works
- when “400-599” and 200 are defined the error is thrown.
It seams that it has issues wtih multiple status codes.
const joiSchema = {
body: {
email: Joi.string()
.lowercase()
.email()
.max(45)
.required(),
password: Joi.string()
.max(10)
.required()
},
output: {
200: {
body: {
jwtToken: Joi.string()
.alphanum()
.min(3)
.max(200)
.required()
}
},
"400-599": {
body: {
error: Joi.object()
}
}
},
type: "json",
continueOnError: true
};
Error: next() called multiple times at dispatch (/home/kresimir/Development/zimmerfrei/zimmerfrei-http-server/node_modules/koa-router/node_modules/koa-compose/index.js:38:45) at next (/home/kresimir/Development/zimmerfrei/zimmerfrei-http-server/node_modules/koa-router/node_modules/koa-compose/index.js:45:18) at errorHandler (/home/kresimir/Development/zimmerfrei/zimmerfrei-http-server/node_modules/koa-joi-router/joi-router.js:285:22) at process._tickCallback (internal/process/next_tick.js:68:7)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Unhandled rejection TypeError: `next()` called multiple times ...
I think this is happening because you have nested then blocks. In your failure case, returning the result of done() in a then...
Read more >How to prevent disasters caused by the callback getting called ...
In this situation execute() is the function of the third party module which I am using, and this callback gets called multiple times...
Read more >Why Is My Future/Async Called Multiple Times? - Flutter Igniter
⁑ callAsyncFetch() gets invoked once per build returning new Future s every time; = didUpdateWidget in the FutureBuilder compares old and new Future...
Read more >MongoDB Compass GUI - Callback called multiple times
I had the same problem as you. Here is an example of how to solve it: [ { "BMW" : ["BMW1", "BMW2", "BMW3"],...
Read more >Events | Node.js v19.3.0 Documentation
EventEmitter; Event listener; EventTarget error handling; Class: Event ... then removeListener() must be called multiple times to remove each instance.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I my case same error is appearing when
continueOnError: true
but the error is not informed by Joi for example an undefined var on handler bodySo, I’ve simple add the validation (for testing) if the error is a joi error in order to continue whenever joi use continueOnError === true, otherwise the error must be thrown
if (!(err.isJoi && spec.validate.continueOnError)) return ctx.throw(err);
The problem is that when you throw an error (either in code explicitly or by runtime) in the route handler, the
errorHandler
catch the error and calls next() which breaks koa’s compose function. Although “an undefined var on handler body” is not a good example, @rolivares 's workaround works for custom errors, which is my case, but won’t work if I throw the Joi error from ctx.invalid as-is, which maybe nobody would really do that, it still should be taken into consideration IMO.