File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,19 @@ import { extractDataFromResponse } from './extractDataFromResponse';
22
33export type QueryParams = Record < string , unknown > ;
44
5+ export class HttpError extends Error {
6+ constructor (
7+ message : string ,
8+ public status : number ,
9+ public statusText : string ,
10+ public responseBody : string ,
11+ public url : string ,
12+ ) {
13+ super ( message ) ;
14+ this . name = 'HttpError' ;
15+ }
16+ }
17+
518export interface RequestConfig {
619 url : string ;
720 method : string ;
@@ -123,8 +136,12 @@ export class HttpClient {
123136
124137 if ( ! response . ok ) {
125138 const errorData = await response . text ( ) ;
126- throw new Error (
127- `Request failed with status ${ response . status } : ${ errorData } ` ,
139+ throw new HttpError (
140+ `Request failed with status ${ response . status } : ${ response . statusText } ` ,
141+ response . status ,
142+ response . statusText ,
143+ errorData ,
144+ response . url ,
128145 ) ;
129146 }
130147
You can’t perform that action at this time.
0 commit comments