| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | import { ErrorResponseImpl } from "./router/utils.js";
|
| 12 |
|
| 13 | const ERROR_DIGEST_BASE = "REACT_ROUTER_ERROR";
|
| 14 | const ERROR_DIGEST_REDIRECT = "REDIRECT";
|
| 15 | const ERROR_DIGEST_ROUTE_ERROR_RESPONSE = "ROUTE_ERROR_RESPONSE";
|
| 16 | function 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 | }
|
| 22 | function 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 |
|
| 29 | export { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest };
|