import type { FetchRequest , FetchResponse } from './fetch' ; export class FetchError < T = any > extends Error { name : 'FetchError' = 'FetchError' ; request ? : FetchRequest ; response ? : FetchResponse < T > ; data ? : T ; } export function createFetchError < T = any > ( request , error ? , response ? ) { let message = '' ; if ( request && response ) { message = `${ response . status } ${ response . statusText } (${ request . toString ( ) })` ; } if ( error ) { message = `${ error . message } (${ message })` ; } const fetchError = new FetchError ( message ) ; Object . defineProperty ( fetchError , 'request' , { get ( ) { return request ; } } ) ; Object . defineProperty ( fetchError , 'response' , { get ( ) { return response ; } } ) ; Object . defineProperty ( fetchError , 'data' , { get ( ) { return response && response . data ; } } ) ; return fetchError ; }