Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
export const HTTPAccessErrorStatus = {
|
|
NOT_FOUND: 404,
|
|
FORBIDDEN: 403,
|
|
UNAUTHORIZED: 401
|
|
};
|
|
const ALLOWED_CODES = new Set(Object.values(HTTPAccessErrorStatus));
|
|
export const HTTP_ERROR_FALLBACK_ERROR_CODE = 'NEXT_HTTP_ERROR_FALLBACK';
|
|
/**
|
|
* Checks an error to determine if it's an error generated by
|
|
* the HTTP navigation APIs `notFound()`, `forbidden()` or `unauthorized()`.
|
|
*
|
|
* @param error the error that may reference a HTTP access error
|
|
* @returns true if the error is a HTTP access error
|
|
*/ export function isHTTPAccessFallbackError(error) {
|
|
if (typeof error !== 'object' || error === null || !('digest' in error) || typeof error.digest !== 'string') {
|
|
return false;
|
|
}
|
|
const [prefix, httpStatus] = error.digest.split(';');
|
|
return prefix === HTTP_ERROR_FALLBACK_ERROR_CODE && ALLOWED_CODES.has(Number(httpStatus));
|
|
}
|
|
export function getAccessFallbackHTTPStatus(error) {
|
|
const httpStatus = error.digest.split(';')[1];
|
|
return Number(httpStatus);
|
|
}
|
|
export function getAccessFallbackErrorTypeByStatus(status) {
|
|
switch(status){
|
|
case 401:
|
|
return 'unauthorized';
|
|
case 403:
|
|
return 'forbidden';
|
|
case 404:
|
|
return 'not-found';
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
//# sourceMappingURL=http-access-fallback.js.map
|