UNPKG

vike

Version:

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

37 lines (36 loc) 1.55 kB
export { handleErrorWithoutErrorPage }; import { stringify } from '@brillout/json-serializer/stringify'; import { assert, assertWarning, objectAssign } from '../utils.js'; import { createHttpResponsePage, createHttpResponseError } from './createHttpResponse.js'; import pc from '@brillout/picocolors'; // When the user hasn't defined _error.page.js async function handleErrorWithoutErrorPage(pageContext) { assert(pageContext.pageId === null); assert(pageContext.errorWhileRendering || pageContext.is404); { const isV1 = pageContext._globalContext._pageConfigs.length > 0; await warnMissingErrorPage(isV1, pageContext._globalContext._isProduction); } if (!pageContext.isClientSideNavigation) { const httpResponse = createHttpResponseError(pageContext); objectAssign(pageContext, { httpResponse }); return pageContext; } else { const __getPageAssets = async () => []; objectAssign(pageContext, { __getPageAssets }); const httpResponse = await createHttpResponsePage(stringify({ serverSideError: true }), null, pageContext); objectAssign(pageContext, { httpResponse }); return pageContext; } } async function warnMissingErrorPage(isV1, isProduction) { if (!isProduction) { const msg = [ `No ${isV1 ? 'error page' : pc.cyan('_error.page.js')} found,`, 'we recommend defining one', 'https://vike.dev/error-page', ].join(' '); assertWarning(false, msg, { onlyOnce: true }); } }