koajs / onerror Goto Github PK
View Code? Open in Web Editor NEWan error handler for koa, hack ctx.onerror
License: MIT License
an error handler for koa, hack ctx.onerror
License: MIT License
You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
AssertionError: non-error thrown: [object Object]
at Object.app.context.onerror (/mnt/api/node_modules/koa-onerror/index.js:38:5)
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
https://github.com/koajs/onerror/blob/master/index.js#L50
if emit error to app.error event listenter, error will both handled by ctx.onerror and app.on('error');
Is that redundant??
const onerror = require('koa-onerror')
const app = new Koa()
onerror(app, {
accepts: 'json',
})
.... occurred an error.
(node:25492) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: options.accepts.call is not a function
(node:25492) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
onerror(app, options) <--- how to set this options to json?
Is it possible to support async render like koa-views for koa2?
looking to use this in koa@next - or a better alternative?
when on error,the default return message is html format, how to configure return json format. Thanks a lot!!
Notice https://github.com/koajs/onerror/blob/master/index.js#L35
I'm using server slide render with koa, what means Error will be thrown from a bundler file, then the Error
instance is not an instance of node Error
.
Then what if I just throw {status: 404}
, follow the code it will be transformed to non-error thrown: [Object object]
, so there will be no way to get the original error message!
Should we just delete this line of code or find another way?
Test:
it('should 404 error ok', function (done) {
var app = koa();
app.on('error', function () {});
onerror(app);
request(app.callback())
.get('/404')
.set('Accept', 'text/html')
.expect(/<p>Looks like something broke!<\/p>/, done);
});
the reason is: https://github.com/koajs/koa/blob/master/lib/application.js#L130
I've just come into contact with koa related technologies, but the instructions in readme seem a little simple. I don't know how to use onerror to customize my own things. Can you explain it
When errror happens, i want response json not render html page.
If any of the project maintainers have time, can you create a @types/koa-error repository, it would be a great help to ts project, if the maintainers don't have time I can help create it too.
I try to return the common's format on error ,but the json of options is disabled
assert.js:98
throw new assert.AssertionError({
^
AssertionError: non-error thrown: false
at Object.app.context.onerror (/Users/mk2/git/personalweb/node_modules/chair/node_modules/koa-onerror/index.js:50:5)
at Socket.done (/Users/mk2/git/personalweb/node_modules/chair/node_modules/koa/node_modules/finished/index.js:15:5)
at Socket.EventEmitter.emit (events.js:126:20)
at TCP.close (net.js:467:12)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.