File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ export class UnleashClient extends TinyEmitter {
150150 private usePOSTrequests = false ;
151151 private started = false ;
152152 private sdkState : SdkState ;
153+ private lastError : any ;
153154
154155 constructor ( {
155156 storageProvider,
@@ -206,6 +207,7 @@ export class UnleashClient extends TinyEmitter {
206207 console . error ( error ) ;
207208 this . sdkState = 'error' ;
208209 this . emit ( EVENTS . ERROR , error ) ;
210+ this . lastError = error ;
209211 resolve ( ) ;
210212 } ) ;
211213 } ) ;
@@ -393,6 +395,14 @@ export class UnleashClient extends TinyEmitter {
393395 this . metrics . stop ( ) ;
394396 }
395397
398+ public isReady ( ) : boolean {
399+ return this . readyEventEmitted ;
400+ }
401+
402+ public getError ( ) : SdkState {
403+ return this . sdkState === 'error' ? this . lastError : undefined ;
404+ }
405+
396406 private async resolveSessionId ( ) : Promise < string > {
397407 if ( this . context . sessionId ) {
398408 return this . context . sessionId ;
@@ -485,6 +495,10 @@ export class UnleashClient extends TinyEmitter {
485495 type : 'HttpError' ,
486496 code : response . status ,
487497 } ) ;
498+ this . lastError = {
499+ type : 'HttpError' ,
500+ code : response . status ,
501+ } ;
488502 }
489503 } catch ( e ) {
490504 if ( ! ( e instanceof DOMException && e . name === 'AbortError' ) ) {
@@ -494,6 +508,7 @@ export class UnleashClient extends TinyEmitter {
494508 ) ;
495509 this . sdkState = 'error' ;
496510 this . emit ( EVENTS . ERROR , e ) ;
511+ this . lastError = e ;
497512 }
498513 } finally {
499514 this . abortController = null ;
You can’t perform that action at this time.
0 commit comments