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 {
150
150
private usePOSTrequests = false ;
151
151
private started = false ;
152
152
private sdkState : SdkState ;
153
+ private lastError : any ;
153
154
154
155
constructor ( {
155
156
storageProvider,
@@ -206,6 +207,7 @@ export class UnleashClient extends TinyEmitter {
206
207
console . error ( error ) ;
207
208
this . sdkState = 'error' ;
208
209
this . emit ( EVENTS . ERROR , error ) ;
210
+ this . lastError = error ;
209
211
resolve ( ) ;
210
212
} ) ;
211
213
} ) ;
@@ -393,6 +395,14 @@ export class UnleashClient extends TinyEmitter {
393
395
this . metrics . stop ( ) ;
394
396
}
395
397
398
+ public isReady ( ) : boolean {
399
+ return this . readyEventEmitted ;
400
+ }
401
+
402
+ public getError ( ) : SdkState {
403
+ return this . sdkState === 'error' ? this . lastError : undefined ;
404
+ }
405
+
396
406
private async resolveSessionId ( ) : Promise < string > {
397
407
if ( this . context . sessionId ) {
398
408
return this . context . sessionId ;
@@ -485,6 +495,10 @@ export class UnleashClient extends TinyEmitter {
485
495
type : 'HttpError' ,
486
496
code : response . status ,
487
497
} ) ;
498
+ this . lastError = {
499
+ type : 'HttpError' ,
500
+ code : response . status ,
501
+ } ;
488
502
}
489
503
} catch ( e ) {
490
504
if ( ! ( e instanceof DOMException && e . name === 'AbortError' ) ) {
@@ -494,6 +508,7 @@ export class UnleashClient extends TinyEmitter {
494
508
) ;
495
509
this . sdkState = 'error' ;
496
510
this . emit ( EVENTS . ERROR , e ) ;
511
+ this . lastError = e ;
497
512
}
498
513
} finally {
499
514
this . abortController = null ;
You can’t perform that action at this time.
0 commit comments