All files / apps/huella-legal/server/plugins errorLog.ts

100% Statements 7/7
100% Branches 10/10
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15      6x 6x     6x 5x     1x      
import type { H3Error } from "h3";
 
export default defineNitroPlugin((nitroApp) => {
    nitroApp.hooks.hook("error", (error, { event, tags }) => {
        const { statusCode = 500, unhandled, fatal } = error as Partial<H3Error>;
 
        // Nitro already prints an unhandled or fatal error, and its cache prints its own failures
        if (!event || !(tags as string[] | undefined)?.includes("request")) return;
        if (unhandled || fatal || statusCode < 500) return;
 
        // eslint-disable-next-line no-console -- a handled 5xx is otherwise invisible in the server log
        console.error(`[request error] [handled] [${event.method}] ${event.path}\n`, error);
    });
});