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