File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 11export type Params = Record < string , string | number | boolean | null >
22
3- export type ErrorResponse = {
4- code : number
5- message : string
6- }
3+ export type ErrorResponse =
4+ | {
5+ code : number
6+ statusCode ?: never
7+ message : string
8+ }
9+ | {
10+ code ?: never
11+ statusCode : number
12+ message : string
13+ }
714
815const isErrorResponse = ( data : unknown ) : data is ErrorResponse => {
916 const isObject = typeof data === 'object' && data !== null
10- return isObject && 'code' in data && 'message' in data
17+ return isObject && ( 'code' in data || 'statusCode' in data ) && 'message' in data
1118}
1219
1320function replaceParam ( str : string , key : string , value : string ) : string {
@@ -48,7 +55,7 @@ async function parseResponse<T>(resp: Response): Promise<T> {
4855
4956 if ( ! resp . ok ) {
5057 const errTxt = isErrorResponse ( json )
51- ? `CGW error - ${ json . code } : ${ json . message } `
58+ ? `CGW error - ${ json . code ?? json . statusCode } : ${ json . message } `
5259 : `CGW error - status ${ resp . statusText } `
5360 throw new Error ( errTxt )
5461 }
You can’t perform that action at this time.
0 commit comments