File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { buildQueryParams } from '@/shared/utils/url' ;
2
2
import { ENV } from './env' ;
3
+ import { HttpError } from '@/shared/errors/HttpError' ;
3
4
4
5
type FetcherOptions < T > = {
5
6
path : string ;
@@ -77,9 +78,8 @@ const request = async <T>({
77
78
const response = await fetch ( url , config ) ;
78
79
79
80
if ( ! response . ok ) {
80
- // const errorData = await response.json().catch(() => null);
81
- // throw new HttpError(response.status, errorData);
82
- throw new Error ( ) ;
81
+ const errorData = await response . json ( ) . catch ( ( ) => null ) ;
82
+ throw new HttpError ( response . status , errorData ) ;
83
83
}
84
84
85
85
if ( response . status === 204 || response . headers . get ( 'content-length' ) === '0' ) {
Original file line number Diff line number Diff line change
1
+ export class HttpError extends Error {
2
+ status : number ;
3
+ data : unknown ;
4
+
5
+ constructor ( status : number , data ?: unknown ) {
6
+ super ( `HTTP Error ${ status } ` ) ;
7
+ this . name = 'HttpError' ;
8
+ this . status = status ;
9
+ this . data = data ;
10
+ }
11
+ }
You can’t perform that action at this time.
0 commit comments