mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
fix: get url from
This commit is contained in:
parent
7c40b7a705
commit
3943a6a9ba
@ -25,16 +25,17 @@ export default defineNitroErrorHandler(
|
|||||||
|
|
||||||
const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true }).toString()
|
const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true }).toString()
|
||||||
// https://github.com/poppinss/youch
|
// https://github.com/poppinss/youch
|
||||||
const youch = new Youch()
|
let youch: Youch | null = null
|
||||||
|
|
||||||
if (import.meta.dev) {
|
if (import.meta.dev) {
|
||||||
|
youch = new Youch()
|
||||||
// Load stack trace with source maps
|
// Load stack trace with source maps
|
||||||
await loadStackTrace(error).catch(consola.error)
|
await loadStackTrace(error).catch(consola.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an error object
|
// Create an error object
|
||||||
const errorObject = {
|
const errorObject = {
|
||||||
url: event.path,
|
url,
|
||||||
statusCode,
|
statusCode,
|
||||||
statusMessage,
|
statusMessage,
|
||||||
message,
|
message,
|
||||||
@ -63,7 +64,7 @@ export default defineNitroErrorHandler(
|
|||||||
process.stdout.columns = 90 // Temporary workaround for youch wrapping issue
|
process.stdout.columns = 90 // Temporary workaround for youch wrapping issue
|
||||||
}
|
}
|
||||||
const ansiError = (
|
const ansiError = (
|
||||||
await youch.toANSI(error)
|
await youch!.toANSI(error)
|
||||||
).replaceAll(process.cwd(), '.')
|
).replaceAll(process.cwd(), '.')
|
||||||
if (!columns) {
|
if (!columns) {
|
||||||
process.stderr.columns = columns
|
process.stderr.columns = columns
|
||||||
@ -90,7 +91,7 @@ export default defineNitroErrorHandler(
|
|||||||
if (isHtml && import.meta.dev) {
|
if (isHtml && import.meta.dev) {
|
||||||
return send(
|
return send(
|
||||||
event,
|
event,
|
||||||
await youch.toHTML(error, {
|
await youch!.toHTML(error, {
|
||||||
request: {
|
request: {
|
||||||
url,
|
url,
|
||||||
method: event.method,
|
method: event.method,
|
||||||
@ -105,16 +106,7 @@ export default defineNitroErrorHandler(
|
|||||||
if (isJsonRequest(event)) {
|
if (isJsonRequest(event)) {
|
||||||
return send(
|
return send(
|
||||||
event,
|
event,
|
||||||
JSON.stringify(
|
JSON.stringify(errorObject,
|
||||||
{
|
|
||||||
error: true,
|
|
||||||
url,
|
|
||||||
statusCode,
|
|
||||||
statusMessage,
|
|
||||||
message: error.message,
|
|
||||||
data: error.data,
|
|
||||||
stack: error.stack?.split('\n').map(line => line.trim()),
|
|
||||||
},
|
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user