{"version":3,"file":"errors-DSpBUWAx.mjs","names":["#frameworkError"],"sources":["../src/next/errors/bailout-to-csr.ts","../src/next/errors/http-access-fallback.ts","../src/next/errors/redirect.ts","../src/next/errors/router.ts","../src/next/errors/dynamic-usage.ts","../src/next/errors/postpone.ts","../src/next/errors/index.ts"],"sourcesContent":["// Comes from https://github.com/vercel/next.js/blob/canary/packages/next/src/shared/lib/lazy-dynamic/bailout-to-csr.ts\n\n// This has to be a shared module which is shared between client component error boundary and dynamic component\nconst BAILOUT_TO_CSR = \"BAILOUT_TO_CLIENT_SIDE_RENDERING\";\n\n/** An error that should be thrown when we want to bail out to client-side rendering. */\nclass BailoutToCSRError extends Error {\n\tpublic readonly digest = BAILOUT_TO_CSR;\n\n\tconstructor(public readonly reason: string) {\n\t\tsuper(`Bail out to client-side rendering: ${reason}`);\n\t}\n}\n\n/** Checks if a passed argument is an error that is thrown if we want to bail out to client-side rendering. */\nexport function isBailoutToCSRError(err: unknown): err is BailoutToCSRError {\n\tif (typeof err !== \"object\" || err === null || !(\"digest\" in err)) {\n\t\treturn false;\n\t}\n\n\treturn err.digest === BAILOUT_TO_CSR;\n}\n","// Comes from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/http-access-fallback/http-access-fallback.ts\n\nconst HTTPAccessErrorStatus = {\n\tNOT_FOUND: 404,\n\tFORBIDDEN: 403,\n\tUNAUTHORIZED: 401,\n};\n\nconst ALLOWED_CODES = new Set(Object.values(HTTPAccessErrorStatus));\n\nconst HTTP_ERROR_FALLBACK_ERROR_CODE = \"NEXT_HTTP_ERROR_FALLBACK\";\n\nexport type HTTPAccessFallbackError = Error & {\n\tdigest: `${typeof HTTP_ERROR_FALLBACK_ERROR_CODE};${string}`;\n};\n\n/**\n * Checks an error to determine if it's an error generated by\n * the HTTP navigation APIs `notFound()`, `forbidden()` or `unauthorized()`.\n *\n * @param error the error that may reference a HTTP access error\n * @returns true if the error is a HTTP access error\n */\nexport function isHTTPAccessFallbackError(error: unknown): error is HTTPAccessFallbackError {\n\tif (typeof error !== \"object\" || error === null || !(\"digest\" in error) || typeof error.digest !== \"string\") {\n\t\treturn false;\n\t}\n\tconst [prefix, httpStatus] = error.digest.split(\";\");\n\n\treturn prefix === HTTP_ERROR_FALLBACK_ERROR_CODE && ALLOWED_CODES.has(Number(httpStatus));\n}\n\nexport function getAccessFallbackHTTPStatus(error: HTTPAccessFallbackError): number {\n\tconst httpStatus = error.digest.split(\";\")[1];\n\treturn Number(httpStatus);\n}\n","// Comes from: https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/redirect-error.ts\n\nenum RedirectStatusCode {\n\tSeeOther = 303,\n\tTemporaryRedirect = 307,\n\tPermanentRedirect = 308,\n}\n\nconst REDIRECT_ERROR_CODE = \"NEXT_REDIRECT\";\n\nenum RedirectType {\n\tpush = \"push\",\n\treplace = \"replace\",\n}\n\nexport type RedirectError = Error & {\n\tdigest: `${typeof REDIRECT_ERROR_CODE};${RedirectType};${string};${RedirectStatusCode};`;\n};\n\n/**\n * Checks an error to determine if it's an error generated by the\n * `redirect(url)` helper.\n *\n * @param error the error that may reference a redirect error\n * @returns true if the error is a redirect error\n */\nexport function isRedirectError(error: unknown): error is RedirectError {\n\tif (typeof error !== \"object\" || error === null || !(\"digest\" in error) || typeof error.digest !== \"string\") {\n\t\treturn false;\n\t}\n\n\tconst digest = error.digest.split(\";\");\n\tconst [errorCode, type] = digest;\n\tconst destination = digest.slice(2, -2).join(\";\");\n\tconst status = digest.at(-2);\n\n\tconst statusCode = Number(status);\n\n\treturn (\n\t\terrorCode === REDIRECT_ERROR_CODE &&\n\t\t(type === \"replace\" || type === \"push\") &&\n\t\ttypeof destination === \"string\" &&\n\t\t!isNaN(statusCode) &&\n\t\tstatusCode in RedirectStatusCode\n\t);\n}\n","// Comes from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/is-next-router-error.ts\n\nimport { isHTTPAccessFallbackError, type HTTPAccessFallbackError } from \"./http-access-fallback\";\nimport { isRedirectError, type RedirectError } from \"./redirect\";\n\n/**\n * Returns true if the error is a navigation signal error. These errors are\n * thrown by user code to perform navigation operations and interrupt the React\n * render.\n */\nexport function isNextRouterError(error: unknown): error is RedirectError | HTTPAccessFallbackError {\n\treturn isRedirectError(error) || isHTTPAccessFallbackError(error);\n}\n","// Comes from https://github.com/vercel/next.js/blob/canary/packages/next/src/export/helpers/is-dynamic-usage-error.ts\n\nimport { isBailoutToCSRError } from \"./bailout-to-csr\";\nimport { isNextRouterError } from \"./router\";\n\nconst DYNAMIC_ERROR_CODE = \"DYNAMIC_SERVER_USAGE\";\n\nclass DynamicServerError extends Error {\n\tdigest: typeof DYNAMIC_ERROR_CODE = DYNAMIC_ERROR_CODE;\n\n\tconstructor(public readonly description: string) {\n\t\tsuper(`Dynamic server usage: ${description}`);\n\t}\n}\n\nfunction isDynamicServerError(err: unknown): err is DynamicServerError {\n\tif (typeof err !== \"object\" || err === null || !(\"digest\" in err) || typeof err.digest !== \"string\") {\n\t\treturn false;\n\t}\n\n\treturn err.digest === DYNAMIC_ERROR_CODE;\n}\n\nfunction isDynamicPostponeReason(reason: string) {\n\treturn (\n\t\treason.includes(\"needs to bail out of prerendering at this point because it used\") &&\n\t\treason.includes(\"Learn more: https://nextjs.org/docs/messages/ppr-caught-error\")\n\t);\n}\n\nfunction isDynamicPostpone(err: unknown) {\n\tif (\n\t\ttypeof err === \"object\" &&\n\t\terr !== null &&\n\t\t// oxlint-disable-next-line\n\t\ttypeof (err as any).message === \"string\"\n\t) {\n\t\t// oxlint-disable-next-line\n\t\treturn isDynamicPostponeReason((err as any).message);\n\t}\n\treturn false;\n}\n\nexport const isDynamicUsageError = (err: unknown) =>\n\tisDynamicServerError(err) || isBailoutToCSRError(err) || isNextRouterError(err) || isDynamicPostpone(err);\n","// Comes from https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/router-utils/is-postpone.ts\n\nconst REACT_POSTPONE_TYPE: symbol = Symbol.for(\"react.postpone\");\n\nexport function isPostpone(error: any): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t// oxlint-disable-next-line\n\t\terror.$$typeof === REACT_POSTPONE_TYPE\n\t);\n}\n","import type { NavigationKind } from \"../../index.types\";\nimport { isBailoutToCSRError } from \"./bailout-to-csr\";\nimport { isDynamicUsageError } from \"./dynamic-usage\";\nimport { getAccessFallbackHTTPStatus, isHTTPAccessFallbackError } from \"./http-access-fallback\";\nimport { isPostpone } from \"./postpone\";\nimport { isRedirectError } from \"./redirect\";\nimport { isNextRouterError } from \"./router\";\n\nexport class FrameworkErrorHandler {\n\t#frameworkError: Error | undefined;\n\n\tstatic isNavigationError(error: unknown): error is Error {\n\t\treturn isNextRouterError(error) || isBailoutToCSRError(error) || isDynamicUsageError(error) || isPostpone(error);\n\t}\n\n\tstatic getNavigationKind(error: Error): NavigationKind {\n\t\tif (isRedirectError(error)) {\n\t\t\treturn \"redirect\";\n\t\t}\n\n\t\tif (isHTTPAccessFallbackError(error)) {\n\t\t\tconst status = getAccessFallbackHTTPStatus(error);\n\t\t\tif (status === 404) return \"notFound\";\n\t\t\tif (status === 403) return \"forbidden\";\n\t\t\tif (status === 401) return \"unauthorized\";\n\t\t}\n\n\t\treturn \"other\";\n\t}\n\n\t// Used in action builder.\n\thandleError(e: unknown) {\n\t\tif (FrameworkErrorHandler.isNavigationError(e)) {\n\t\t\tthis.#frameworkError = e;\n\t\t\treturn;\n\t\t}\n\n\t\t// If it's not a framework error, rethrow it, so it gets returned as a server error.\n\t\tthrow e;\n\t}\n\n\tget error() {\n\t\treturn this.#frameworkError;\n\t}\n}\n"],"mappings":";AAGA,MAAM,iBAAiB;;AAYvB,SAAgB,oBAAoB,KAAwC;AAC3E,KAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,EAAE,YAAY,KAC5D,QAAO;AAGR,QAAO,IAAI,WAAW;;;;ACZvB,MAAM,gBAAgB,IAAI,IAAI,OAAO,OANP;CAC7B,WAAW;CACX,WAAW;CACX,cAAc;CACd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