@@ -4,7 +4,7 @@ import { buildEnvironmentModel } from '../flagsmith-engine/environments/util.js'
44
55import { ANALYTICS_ENDPOINT , AnalyticsProcessor } from './analytics.js' ;
66import { BaseOfflineHandler } from './offline_handlers.js' ;
7- import { FlagsmithAPIError } from './errors.js' ;
7+ import { FlagsmithAPIError , FlagsmithClientError } from './errors.js' ;
88
99import { DefaultFlag , Flags } from './models.js' ;
1010import { EnvironmentDataPollingManager } from './polling_manager.js' ;
@@ -279,6 +279,9 @@ export class Flagsmith {
279279 ) ;
280280
281281 const context = getEvaluationContext ( environment , identityModel ) ;
282+ if ( ! context ) {
283+ throw new FlagsmithClientError ( 'Local evaluation required to obtain identity segments' ) ;
284+ }
282285 const evaluationResult = getEvaluationResult ( context ) ;
283286
284287 return SegmentModel . fromSegmentResult ( evaluationResult . segments , context ) ;
@@ -401,6 +404,9 @@ export class Flagsmith {
401404 private async getEnvironmentFlagsFromDocument ( ) : Promise < Flags > {
402405 const environment = await this . getEnvironment ( ) ;
403406 const context = getEvaluationContext ( environment ) ;
407+ if ( ! context ) {
408+ throw new FlagsmithClientError ( 'Unable to get flags. No environment present.' ) ;
409+ }
404410 const evaluationResult = getEvaluationResult ( context ) ;
405411 const flags = Flags . fromEvaluationResult ( evaluationResult ) ;
406412
@@ -426,6 +432,9 @@ export class Flagsmith {
426432 ) ;
427433
428434 const context = getEvaluationContext ( environment , identityModel ) ;
435+ if ( ! context ) {
436+ throw new FlagsmithClientError ( 'Unable to get flags. No environment present.' ) ;
437+ }
429438 const evaluationResult = getEvaluationResult ( context ) ;
430439
431440 const flags = Flags . fromEvaluationResult (
0 commit comments