File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
packages/remote-config/src Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
2424import { ERROR_FACTORY , ErrorCode } from '../errors' ;
2525import { getUserLanguage } from '../language' ;
2626import { _FirebaseInstallationsInternal } from '@firebase/installations' ;
27+ import { isBrowser } from '@firebase/util' ;
2728
2829/**
2930 * Defines request body parameters required to call the fetch API:
@@ -65,8 +66,13 @@ export class RestClient implements RemoteConfigFetchClient {
6566 * @throws a {@link ErrorCode.FETCH_PARSE} error if {@link Response#json} can't parse the
6667 * fetch response.
6768 * @throws a {@link ErrorCode.FETCH_STATUS} error if the service returns an HTTP error status.
69+ * @throws a {@link ErrorCode.REQUIRES_BROWSER_ENVIRONMENT} error if the invoked in a non browser
70+ * environment.
6871 */
6972 async fetch ( request : FetchRequest ) : Promise < FetchResponse > {
73+ if ( ! isBrowser ( ) ) {
74+ throw ERROR_FACTORY . create ( ErrorCode . REQUIRES_BROWSER_ENVIRONMENT ) ;
75+ }
7076 const [ installationId , installationToken ] = await Promise . all ( [
7177 this . firebaseInstallations . getId ( ) ,
7278 this . firebaseInstallations . getToken ( )
Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ export const enum ErrorCode {
3131 FETCH_THROTTLE = 'fetch-throttle' ,
3232 FETCH_PARSE = 'fetch-client-parse' ,
3333 FETCH_STATUS = 'fetch-status' ,
34- INDEXED_DB_UNAVAILABLE = 'indexed-db-unavailable'
34+ INDEXED_DB_UNAVAILABLE = 'indexed-db-unavailable' ,
35+ REQUIRES_BROWSER_ENVIRONMENT = 'requires-browser-environment'
3536}
3637
3738const ERROR_DESCRIPTION_MAP : { readonly [ key in ErrorCode ] : string } = {
@@ -67,7 +68,9 @@ const ERROR_DESCRIPTION_MAP: { readonly [key in ErrorCode]: string } = {
6768 [ ErrorCode . FETCH_STATUS ] :
6869 'Fetch server returned an HTTP error status. HTTP status: {$httpStatus}.' ,
6970 [ ErrorCode . INDEXED_DB_UNAVAILABLE ] :
70- 'Indexed DB is not supported by current browser'
71+ 'Indexed DB is not supported by current browser' ,
72+ [ ErrorCode . REQUIRES_BROWSER_ENVIRONMENT ] :
73+ 'The requested operation must be executed in a browser environment'
7174} ;
7275
7376// Note this is effectively a type system binding a code to params. This approach overlaps with the
You can’t perform that action at this time.
0 commit comments