17 lines
563 B
TypeScript
17 lines
563 B
TypeScript
import type { H3Error } from 'h3'
|
|
|
|
// Due to a bug in nitro, the stack trace is missing on the server side (https://github.com/nuxt/nuxt/issues/30102)
|
|
export default defineNitroPlugin((nitroApp) => {
|
|
nitroApp.hooks.hook('error', (error, { event }) => {
|
|
const statusCode = (error as H3Error)?.statusCode
|
|
if (statusCode && statusCode >= 500) {
|
|
console.error(`[${statusCode}] ${event?.path}`, error)
|
|
}
|
|
|
|
// Print out all errors that are not HTTP errors
|
|
if (!statusCode) {
|
|
console.error(`[Error] ${event?.path}`, error)
|
|
}
|
|
})
|
|
})
|