Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support customize error handler (#26)
- Loading branch information
1 parent
37c06ce
commit 4a1b770
Showing
8 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
exports.index = function* () { | ||
const err = new Error('test error'); | ||
if (this.query.code) { | ||
err.code = this.query.code; | ||
} | ||
if (this.query.status) { | ||
err.status = Number(this.query.status); | ||
} | ||
if (this.query.message) { | ||
err.message = this.query.message; | ||
} | ||
throw err; | ||
}; | ||
|
||
exports.csrf = function* () { | ||
this.set('x-csrf', this.csrf); | ||
this.body = 'test'; | ||
}; | ||
|
||
exports.test = function* () { | ||
const err = new SyntaxError('syntax error'); | ||
if (this.query.status) { | ||
err.status = Number(this.query.status); | ||
} | ||
throw err; | ||
}; | ||
|
||
exports.jsonp = function* () { | ||
throw new Error('jsonp error'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
module.exports = function* () { | ||
const err = new Error('test error'); | ||
if (this.query.status) { | ||
err.status = Number(this.query.status); | ||
} | ||
if (this.query.errors) { | ||
err.errors = this.query.errors; | ||
} | ||
throw err; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
app.get('/', app.controller.home.index); | ||
app.get('/csrf', app.controller.home.csrf); | ||
app.post('/test', app.controller.home.test); | ||
app.get('/user', app.controller.user); | ||
app.get('/user.json', app.controller.user); | ||
app.get('/jsonp', app.jsonp(), app.controller.home.jsonp); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
exports.onerror = { | ||
errorPageUrl: 'https://eggjs.com/500.html', | ||
json(err, ctx) { | ||
ctx.body = { msg: 'error' }; | ||
ctx.status = 500; | ||
}, | ||
}; | ||
|
||
exports.logger = { | ||
level: 'NONE', | ||
consoleLevel: 'NONE', | ||
}; | ||
|
||
exports.keys = 'foo,bar'; | ||
|
||
exports.security = { | ||
csrf: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "onerror-customize" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters