UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

35 lines (34 loc) 1.79 kB
"use strict"; // Logger used for the production server. // Any other environment (dev, preview, build, and pre-rendering) uses loggerNotProd.ts instead. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.logErrorProd = logErrorProd; exports.onRuntimeError = onRuntimeError; const abort_js_1 = require("../../../shared/route/abort.js"); const isNewError_js_1 = require("./isNewError.js"); const utils_js_1 = require("../utils.js"); const picocolors_1 = __importDefault(require("@brillout/picocolors")); const logErrorHint_js_1 = require("./logErrorHint.js"); function logErrorProd(err, _httpRequestId) { (0, utils_js_1.warnIfErrorIsNotObject)(err); (0, isNewError_js_1.setAlreadyLogged)(err); if ((0, abort_js_1.isAbortError)(err)) { return; } // We ensure we print a string; Cloudflare Workers doesn't seem to properly stringify `Error` objects. const errStr = (0, utils_js_1.isObject)(err) && 'stack' in err ? String(err.stack) : String(err); console.error(picocolors_1.default.red(errStr)); // Needs to be called after logging the error. onRuntimeError(err); } // Every server-side runtime error is expected to go through `onRuntimeError()`. // - onRuntimeError(err) should always be called after `console.error(err)`. // - Because the error hint of logErrorHint(err) should be shown *after* the error. // - In principle, any runtime error is (or at least should) be caught by Vike, otherwise Vike couldn't render the error page. function onRuntimeError(err) { // The more runtime errors we pass to logErrorHint() the better. (0, logErrorHint_js_1.logErrorHint)(err); }