mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
more consistent errors
This commit is contained in:
parent
b7715dc288
commit
25fdb28d41
@ -277,14 +277,15 @@ export default class Renderer extends Tapable {
|
||||
}
|
||||
|
||||
errorMiddleware (err, req, res, next) {
|
||||
// ensure statusCode and message
|
||||
// ensure statusCode, message and name fields
|
||||
err.statusCode = err.statusCode || 500
|
||||
err.message = err.message || 'Nuxt Server Error'
|
||||
err.name = err.name || 'Nuxt Server Error'
|
||||
|
||||
const sendResponse = (content, type = 'text/html') => {
|
||||
// Set Headers
|
||||
res.statusCode = err.statusCode
|
||||
res.statusMessage = err.message
|
||||
res.statusMessage = err.name
|
||||
res.setHeader('Content-Type', type + '; charset=utf-8')
|
||||
res.setHeader('Content-Length', Buffer.byteLength(content))
|
||||
|
||||
@ -301,7 +302,7 @@ export default class Renderer extends Tapable {
|
||||
const json = {
|
||||
status: err.statusCode,
|
||||
message: err.message,
|
||||
name: 'Nuxt Server Error'
|
||||
name: err.name
|
||||
}
|
||||
if (isJson) {
|
||||
sendResponse(JSON.stringify(json, undefined, 2), 'text/json')
|
||||
@ -313,8 +314,6 @@ export default class Renderer extends Tapable {
|
||||
}
|
||||
|
||||
// Show stack trace
|
||||
err.name = 'Nuxt Server Error'
|
||||
err.status = 500
|
||||
const youch = new Youch(err, req, this.readSource.bind(this))
|
||||
if (isJson) {
|
||||
youch.toJSON().then(json => { sendResponse(JSON.stringify(json, undefined, 2), 'text/json') })
|
||||
|
Loading…
Reference in New Issue
Block a user