@@ -21,7 +21,12 @@ import {
2121 HttpRequestConfig , HttpClient , RequestResponseError , AuthorizedHttpClient
2222} from '../utils/api-request' ;
2323import { FirebaseError , toHttpResponse } from '../utils/error' ;
24- import { FirebaseDataConnectError , DataConnectErrorCode , DATA_CONNECT_ERROR_CODE_MAPPING } from './error' ;
24+ import {
25+ FirebaseDataConnectError ,
26+ DataConnectErrorCode ,
27+ DATA_CONNECT_ERROR_CODE_MAPPING ,
28+ GRPC_STATUS_CODE_TO_STRING
29+ } from './error' ;
2530import * as utils from '../utils/index' ;
2631import * as validator from '../utils/validator' ;
2732import { ConnectorConfig , ExecuteGraphqlResponse , GraphqlOptions , OperationOptions } from './data-connect-api' ;
@@ -409,10 +414,17 @@ export class DataConnectApiClient {
409414 } ) ;
410415 }
411416
412- const error : ServerError = ( response . data as ErrorResponse ) . error || { } ;
417+ const data = response . data as any ;
418+ const error : ServerError = ( validator . isNonNullObject ( data ) && 'error' in data ) ? data . error : data || { } ;
419+
420+ let status = error . status ;
421+ if ( ! status && validator . isNumber ( error . code ) ) {
422+ status = GRPC_STATUS_CODE_TO_STRING [ error . code as number ] ;
423+ }
424+
413425 let code : DataConnectErrorCode = DATA_CONNECT_ERROR_CODE_MAPPING . UNKNOWN ;
414- if ( error . status && error . status in DATA_CONNECT_ERROR_CODE_MAPPING ) {
415- code = DATA_CONNECT_ERROR_CODE_MAPPING [ error . status ] ;
426+ if ( status && status in DATA_CONNECT_ERROR_CODE_MAPPING ) {
427+ code = DATA_CONNECT_ERROR_CODE_MAPPING [ status ] ;
416428 }
417429 const message = error . message || 'Unknown server error' ;
418430 return new FirebaseDataConnectError ( {
@@ -670,10 +682,6 @@ export function useEmulator(): boolean {
670682 return ! ! emulatorHost ( ) ;
671683}
672684
673- interface ErrorResponse {
674- error ?: ServerError ;
675- }
676-
677685interface ServerError {
678686 code ?: number ;
679687 message ?: string ;
0 commit comments