fix(nuxt): normalise error url to pathname

This commit is contained in:
Daniel Roe 2025-03-06 23:14:59 +00:00
parent d5588dbb8c
commit 87b69c9ae5
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -29,6 +29,10 @@ export default <NitroErrorHandler> async function errorhandler (error, event, {
}
const errorObject = defaultRes.body as Pick<NonNullable<NuxtPayload['error']>, 'error' | 'statusCode' | 'statusMessage' | 'message' | 'stack'> & { url: string, data: any }
// remove proto/hostname/port from URL
const url = new URL(errorObject.url)
errorObject.url = url.pathname + url.search + url.hash
// add default server message
errorObject.message ||= 'Server Error'
delete defaultRes.headers['content-type'] // this would be set to application/json