File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -15,15 +15,12 @@ export function handleUnsuccessfulApiResponse<T extends SocketSdkOperations>(
15
15
result : SocketSdkErrorType < T > ,
16
16
spinner : Spinner
17
17
) {
18
- const resultError =
19
- 'error' in result && result . error && typeof result . error === 'object'
20
- ? result . error
21
- : { }
18
+ // SocketSdkErrorType['error'] is not typed.
19
+ const resultErrorMessage = ( < { error ?: Error } > result ) . error ?. message
22
20
const message =
23
- 'message' in resultError && typeof resultError . message === 'string'
24
- ? resultError . message
21
+ typeof resultErrorMessage === 'string'
22
+ ? resultErrorMessage
25
23
: 'No error message returned'
26
-
27
24
if ( result . status === 401 || result . status === 403 ) {
28
25
spinner . stop ( )
29
26
throw new AuthError ( message )
@@ -51,17 +48,17 @@ export async function handleApiCall<T>(
51
48
52
49
export async function handleAPIError ( code : number ) {
53
50
if ( code === 400 ) {
54
- return ` One of the options passed might be incorrect.`
51
+ return ' One of the options passed might be incorrect.'
55
52
} else if ( code === 403 ) {
56
- return ` You might be trying to access an organization that is not linked to the API key you are logged in with.`
53
+ return ' You might be trying to access an organization that is not linked to the API key you are logged in with.'
57
54
}
58
55
}
59
56
60
57
export async function queryAPI ( path : string , apiKey : string ) {
61
58
return await fetch ( `${ API_V0_URL } /${ path } ` , {
62
59
method : 'GET' ,
63
60
headers : {
64
- Authorization : ' Basic ' + btoa ( `${ apiKey } :${ apiKey } ` )
61
+ Authorization : ` Basic ${ btoa ( `${ apiKey } :${ apiKey } ` ) } `
65
62
}
66
63
} )
67
64
}
You can’t perform that action at this time.
0 commit comments