@ashraflabs/use-api
Version:
A simple and powerful custom React hook (useApi) that simplifies API requests with automatic loading and error states. Ideal for clean and maintainable data fetching in React components.
20 lines (19 loc) • 622 B
JavaScript
/**
* A custom error class for Fetch API errors, including HTTP and network errors.
* @example
* throw new FetchError("HTTP error! Status: 404", response, 404);
*/
export class FetchError extends Error {
/**
* Creates a new FetchError instance.
* @param message The error message.
* @param response The Fetch API Response object, if available.
* @param status The HTTP status code, if applicable.
*/
constructor(message, response = null, status = null) {
super(message);
this.name = 'FetchError';
this.response = response;
this.status = status;
}
}