{"version":3,"file":"next-http-errors.cjs","sources":["../../../src/lib/next-http-errors.ts"],"sourcesContent":["// from https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/http-access-fallback/http-access-fallback.ts\n\nexport const HTTPAccessErrorStatus = {\n  NOT_FOUND: 404,\n  FORBIDDEN: 403,\n  UNAUTHORIZED: 401,\n};\n\nconst ALLOWED_CODES = new Set(Object.values(HTTPAccessErrorStatus));\n\nexport const HTTP_ERROR_FALLBACK_ERROR_CODE = 'NEXT_HTTP_ERROR_FALLBACK';\n\nexport type HTTPAccessFallbackError = Error & {\n  digest: `${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  if (typeof error !== 'object' || error === null || !('digest' in error) || typeof error.digest !== 'string') {\n    return false;\n  }\n  const [prefix, httpStatus] = error.digest.split(';');\n\n  return prefix === HTTP_ERROR_FALLBACK_ERROR_CODE && ALLOWED_CODES.has(Number(httpStatus));\n}\n\nexport function getAccessFallbackHTTPStatus(error: HTTPAccessFallbackError | NotFoundError): number {\n  if (isNotFoundError(error)) {\n    return 404;\n  }\n  const httpStatus = error.digest.split(';')[1];\n  return Number(httpStatus);\n}\n\nexport function getAccessFallbackErrorTypeByStatus(\n  status: number,\n): 'not-found' | 'forbidden' | 'unauthorized' | undefined {\n  switch (status) {\n    case 401:\n      return 'unauthorized';\n    case 403:\n      return 'forbidden';\n    case 404:\n      return 'not-found';\n    default:\n      return;\n  }\n}\n\n// Legacy notFound()\n\nconst NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND';\n\ntype NotFoundError = Error & { digest: typeof NOT_FOUND_ERROR_CODE };\n\n/**\n * Checks an error to determine if it's an error generated by the `notFound()`\n * helper.\n *\n * @param error the error that may reference a not found error\n * @returns true if the error is a not found error\n */\nexport function isNotFoundError(error: unknown): error is NotFoundError {\n  if (typeof error !== 'object' || error === null || !('digest' in error)) {\n    return false;\n  }\n\n  return error.digest === NOT_FOUND_ERROR_CODE;\n}\n"],"names":[],"mappings":";;AAEO,MAAM,wBAAwB;AAAA,EACnC,WAAW;AAAA,EACX,WAAW;AAAA,EACX,cAAc;AAChB;AAEA,MAAM,gBAAgB,IAAI,IAAI,OAAO,OAAO,qBAAqB,CAAC;AAE3D,MAAM,iCAAiC;AAavC,SAAS,0BAA0B,OAAkD;AAC1F,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,YAAY,UAAU,OAAO,MAAM,WAAW,UAAU;AAC3G,WAAO;AAAA,EACT;AACA,QAAM,CAAC,QAAQ,UAAU,IAAI,MAAM,OAAO,MAAM,GAAG;AAEnD,SAAO,WAAW,kCAAkC,cAAc,IAAI,OAAO,UAAU,CAAC;AAC1F;AAEO,SAAS,4BAA4B,OAAwD;AAClG,MAAI,gBAAgB,KAAK,GAAG;AAC1B,WAAO;AAAA,EACT;AACA,QAAM,aAAa,MAAM,OAAO,MAAM,GAAG,EAAE,CAAC;AAC5C,SAAO,OAAO,UAAU;AAC1B;AAmBA,MAAM,uBAAuB;AAWtB,SAAS,gBAAgB,OAAwC;AACtE,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,YAAY,QAAQ;AACvE,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,WAAW;AAC1B;;;;;;"}