Creates a new AuthError.
Human‑readable error description (must be non‑empty string).
One of the predefined AuthErrorCode values.
Optionaloptions: { cause?: unknown; context?: string }Optional additional data.
Optionalcause?: unknownUnderlying error or response object.
Optionalcontext?: stringShort contextual string (will be trimmed).
StaticfromCreates an AuthError from a fetch Response object.
Maps the HTTP status code to an appropriate error code using
HTTP_STATUS_CODE_MAP, falling back to defaultCode if no mapping exists.
The error message includes the status and statusText, plus an optional context
snippet.
The Response object from a failed fetch.
Fallback error code when no HTTP mapping is available.
Optionaloptions: { context?: string }Optional context string.
A new AuthError instance.
StaticfromCreates an AuthError from any unknown error value.
Intelligently extracts a message and code based on error type:
DOMException with AbortError → TIMEOUTTypeError with fetch in message → NETWORK_ERRORError → inspects message for keywords "csrf", "network", "timeout"The unknown error value (exception, string, etc.).
Code to use if none can be inferred (default: UNKNOWN).
A properly constructed AuthError.
StaticfromCreates an AuthError from a raw HTTP status code and optional response body.
Useful when you have only the status code and a text snippet (e.g., from a
failed XMLHttpRequest or a non‑standard response).
HTTP status code (100‑599).
Optionalbody: stringOptional response body (first line, first 100 chars used).
A new AuthError instance.
Returns a formatted, human‑readable error message.
Format: [CODE] message | Context: ... | Cause: ...
A single string combining code, message, optional context, and cause.
Standard error class for all authentication operations.
Extends the built-in
Errorand adds a typed error code, an optional contextstring, and a timestamp. Instances are frozen to prevent accidental mutation.
Remarks
AuthError.fromStatus to create instances consistently.
toJSON()method provides a safe serialization for logging.getFormattedMessage()returns a human‑readable string with code, context,and cause.
Example
Since
0.1.1