@@ -8,7 +8,7 @@ export class TableDataClient {
88 async postGetData < T , U = Record < string , unknown > | undefined > (
99 request : TableDataRequest ,
1010 formParts : Record < string , string > = { }
11- ) : Promise < BugSplatResponse < TableDataResponse < T , U > > | ErrorResponse > {
11+ ) : Promise < BugSplatResponse < TableDataResponse < T , U > > | BugSplatResponse < ErrorResponse > > {
1212 const factory = ( ) => this . _apiClient . createFormData ( ) ;
1313 const formData = new TableDataFormDataBuilder ( factory , formParts )
1414 . withDatabase ( request . database )
@@ -32,7 +32,7 @@ export class TableDataClient {
3232
3333 async getData < T , U = Record < string , unknown > | undefined > (
3434 request : TableDataRequest
35- ) : Promise < BugSplatResponse < TableDataResponse < T , U > > | ErrorResponse > {
35+ ) : Promise < BugSplatResponse < TableDataResponse < T , U > > | BugSplatResponse < ErrorResponse > > {
3636 const factory = ( ) => this . _apiClient . createFormData ( ) ;
3737 const formData = new TableDataFormDataBuilder ( factory )
3838 . withDatabase ( request . database )
@@ -56,14 +56,14 @@ export class TableDataClient {
5656 private async makeRequest < T , U = unknown > (
5757 url : string ,
5858 init : RequestInit
59- ) : Promise < BugSplatResponse < TableDataResponse < T , U > > | ErrorResponse > {
60- const response = await this . _apiClient . fetch < TableDataResponse < T , U > > ( url , init ) ;
59+ ) : Promise < BugSplatResponse < TableDataResponse < T , U > > | BugSplatResponse < ErrorResponse > > {
60+ const response = await this . _apiClient . fetch < TableDataResponse < T , U > | ErrorResponse > ( url , init ) ;
6161
62- if ( isErrorResponse ( response ) ) {
63- return response ;
62+ if ( response . status !== 200 ) {
63+ return response as unknown as BugSplatResponse < ErrorResponse > ;
6464 }
6565
66- const responseData = await response . json ( ) ;
66+ const responseData = await response . json ( ) as TableDataResponse < T , U > ;
6767 const rows = responseData . rows || [ ] ;
6868 const pageData = responseData . pageData || { } ;
6969 const status = response . status ;
@@ -82,8 +82,14 @@ export class TableDataClient {
8282
8383export type ErrorResponse = { status : number ; message : string } ;
8484
85- export const isErrorResponse = (
86- response : BugSplatResponse < unknown > | ErrorResponse
87- ) : response is ErrorResponse => {
85+ export function isSuccessResponse < T , U = Record < string , unknown > | undefined > (
86+ response : BugSplatResponse < TableDataResponse < T , U > | ErrorResponse >
87+ ) : response is BugSplatResponse < TableDataResponse < T , U > > {
88+ return 'status' in response && response . status === 200 ;
89+ }
90+
91+ export function isErrorResponse < T , U = Record < string , unknown > | undefined > (
92+ response : BugSplatResponse < TableDataResponse < T , U > | ErrorResponse >
93+ ) : response is BugSplatResponse < ErrorResponse > {
8894 return 'status' in response && response . status !== 200 ;
89- } ;
95+ }
0 commit comments