File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -25,23 +25,27 @@ export async function requestAPI(
2525 try {
2626 response = await ServerConnection . makeRequest ( requestUrl , init , settings ) ;
2727 } catch ( error ) {
28- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29- throw new ServerConnection . NetworkError ( error as any ) ;
28+ throw new ServerConnection . NetworkError (
29+ error instanceof Error ? error : new Error ( String ( error ) )
30+ ) ;
3031 }
3132
32- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33- let data : any = await response . text ( ) ;
33+ let data : string | unknown = await response . text ( ) ;
3434
35- if ( data . length > 0 ) {
35+ if ( typeof data === 'string' && data . length > 0 ) {
3636 try {
3737 data = JSON . parse ( data ) ;
38- } catch ( error ) {
38+ } catch {
3939 console . log ( 'Not a JSON response body.' , response ) ;
4040 }
4141 }
4242
4343 if ( ! response . ok ) {
44- throw new ServerConnection . ResponseError ( response , data . message ?? data ) ;
44+ const errorMessage =
45+ data && typeof data === 'object' && 'message' in data
46+ ? ( data as { message : string } ) . message
47+ : String ( data ) ;
48+ throw new ServerConnection . ResponseError ( response , errorMessage ) ;
4549 }
4650
4751 return data ;
You can’t perform that action at this time.
0 commit comments