@wristband/react-client-auth
Version:
A lightweight React SDK that pairs with your backend server auth to initialize and sync frontend sessions via secure session cookies.
33 lines (30 loc) • 1.03 kB
JavaScript
;
/**
* Custom error class for API-related errors with additional HTTP context. Extends the standard Error class with
* properties that provide more information about the HTTP error that occurred.
*
* @class ApiError
* @extends {Error}
* @property {number} [status] - The HTTP status code associated with the error.
* @property {string} [statusText] - The status text from the HTTP response (e.g., "Not Found", "Internal Server Error").
* @property {Response} [response] - The original Response object from the fetch call, which may contain additional information about the error.
*
* @example
* try {
* await apiClient.get('/some-endpoint');
* } catch (error) {
* if (error instanceof ApiError && error.status === 401) {
* console.log(`Authentication error: ${error.statusText}`);
* }
* }
*/
class ApiError extends Error {
status;
statusText;
response;
constructor(message) {
super(message);
this.name = 'ApiError';
}
}
exports.ApiError = ApiError;