release: @marketplaces/auth 0.1.0 (built from main)
This commit is contained in:
24
dist/ed25519/models/auth-error.model.js
vendored
Normal file
24
dist/ed25519/models/auth-error.model.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/** Maps a backend error envelope's `error.code` to the client's AuthErrorCode screens. Only codes with a dedicated screen are mapped; anything else falls back to the HTTP-status-derived code via authErrorCodeFromStatus. */
|
||||
const BACKEND_ERROR_CODE_MAP = {
|
||||
TOKEN_EXPIRED: 'session-expired',
|
||||
INVALID_SIGNATURE: 'invalid-signature',
|
||||
UNAUTHENTICATED: 'unauthorized',
|
||||
FORBIDDEN: 'forbidden',
|
||||
SERVICE_UNAVAILABLE: 'backend-unavailable',
|
||||
};
|
||||
export function authErrorCodeFromBackendCode(code) {
|
||||
return typeof code === 'string' ? BACKEND_ERROR_CODE_MAP[code] : undefined;
|
||||
}
|
||||
/** Maps a backend HTTP status to the AuthErrorCode screen it should route to. */
|
||||
export function authErrorCodeFromStatus(status) {
|
||||
switch (status) {
|
||||
case 401:
|
||||
return 'unauthorized';
|
||||
case 403:
|
||||
return 'forbidden';
|
||||
case 0:
|
||||
return 'backend-unavailable';
|
||||
default:
|
||||
return status >= 500 ? 'backend-unavailable' : 'unauthorized';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user