fix: get url from event.path

This commit is contained in:
Saeid Zareie 2025-01-16 12:10:10 +03:30
parent 3943a6a9ba
commit c7d7992778

View File

@ -4,7 +4,6 @@ import type { H3Event } from 'h3'
import { import {
getRequestHeader, getRequestHeader,
getRequestHeaders, getRequestHeaders,
getRequestURL,
getResponseHeader, getResponseHeader,
send, send,
setResponseHeader, setResponseHeader,
@ -23,7 +22,6 @@ export default defineNitroErrorHandler(
async function defaultNitroErrorHandler (error, event) { async function defaultNitroErrorHandler (error, event) {
const { stack, message, isSensitive, statusCode, statusMessage } = normalizeError(error) const { stack, message, isSensitive, statusCode, statusMessage } = normalizeError(error)
const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true }).toString()
// https://github.com/poppinss/youch // https://github.com/poppinss/youch
let youch: Youch | null = null let youch: Youch | null = null
@ -35,7 +33,7 @@ export default defineNitroErrorHandler(
// Create an error object // Create an error object
const errorObject = { const errorObject = {
url, url: event.path,
statusCode, statusCode,
statusMessage, statusMessage,
message, message,
@ -66,6 +64,7 @@ export default defineNitroErrorHandler(
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
} }
@ -75,7 +74,7 @@ export default defineNitroErrorHandler(
errorToLog = error.message || error.toString() || 'internal server error' errorToLog = error.message || error.toString() || 'internal server error'
} }
console.error(`${tags} [${event.method}] ${url}\n\n`, errorToLog) console.error(`${tags} [${event.method}] ${event.path}\n\n`, errorToLog)
} }
if (event.handled) { return } if (event.handled) { return }
@ -93,7 +92,7 @@ export default defineNitroErrorHandler(
event, event,
await youch!.toHTML(error, { await youch!.toHTML(error, {
request: { request: {
url, url: event.path,
method: event.method, method: event.method,
headers: getRequestHeaders(event), headers: getRequestHeaders(event),
}, },