Custom error class for HTTP error responses (non-2xx status codes).
Thrown when Response.ok is false. Contains the HTTP status code for programmatic error handling.
Response.ok
false
import { fetchT, FetchError } from '@happy-ts/fetch-t';const result = await fetchT('https://api.example.com/not-found', { responseType: 'json',});result.inspectErr((err) => { if (err instanceof FetchError) { console.log('HTTP Status:', err.status); // e.g., 404 console.log('Status Text:', err.message); // e.g., "Not Found" // Handle specific status codes switch (err.status) { case 401: console.log('Unauthorized - please login'); break; case 404: console.log('Resource not found'); break; case 500: console.log('Server error'); break; } }}); Copy
import { fetchT, FetchError } from '@happy-ts/fetch-t';const result = await fetchT('https://api.example.com/not-found', { responseType: 'json',});result.inspectErr((err) => { if (err instanceof FetchError) { console.log('HTTP Status:', err.status); // e.g., 404 console.log('Status Text:', err.message); // e.g., "Not Found" // Handle specific status codes switch (err.status) { case 401: console.log('Unauthorized - please login'); break; case 404: console.log('Resource not found'); break; case 500: console.log('Server error'); break; } }});
Creates a new FetchError instance.
The status text from the HTTP response (e.g., "Not Found").
The HTTP status code (e.g., 404).
The error name, always 'FetchError'.
'FetchError'
The HTTP status code of the response (e.g., 404, 500).
Custom error class for HTTP error responses (non-2xx status codes).
Thrown when
Response.okisfalse. Contains the HTTP status code for programmatic error handling.Example