UNPKG

1.39 kBJavaScriptView Raw
1/**
2 * react-router v8.0.0
3 *
4 * Copyright (c) Remix Software Inc.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE.md file in the root directory of this source tree.
8 *
9 * @license MIT
10 */
11import { ErrorResponseImpl } from "./router/utils.js";
12//#region lib/errors.ts
13const ERROR_DIGEST_BASE = "REACT_ROUTER_ERROR";
14const ERROR_DIGEST_REDIRECT = "REDIRECT";
15const ERROR_DIGEST_ROUTE_ERROR_RESPONSE = "ROUTE_ERROR_RESPONSE";
16function decodeRedirectErrorDigest(digest) {
17 if (digest.startsWith(`${ERROR_DIGEST_BASE}:${ERROR_DIGEST_REDIRECT}:{`)) try {
18 let parsed = JSON.parse(digest.slice(28));
19 if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string" && typeof parsed.location === "string" && typeof parsed.reloadDocument === "boolean" && typeof parsed.replace === "boolean") return parsed;
20 } catch {}
21}
22function decodeRouteErrorResponseDigest(digest) {
23 if (digest.startsWith(`${ERROR_DIGEST_BASE}:${ERROR_DIGEST_ROUTE_ERROR_RESPONSE}:{`)) try {
24 let parsed = JSON.parse(digest.slice(40));
25 if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string") return new ErrorResponseImpl(parsed.status, parsed.statusText, parsed.data);
26 } catch {}
27}
28//#endregion
29export { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest };