Skip to content

Commit 4c89f1f

Browse files
committed
Minor refactoring
1 parent ae305f7 commit 4c89f1f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,9 @@ class StaticServer {
410410
}
411411

412412
async _handleAppStateChange(appState: AppStateStatus) {
413+
const starting = appState === 'active';
413414
try {
414-
if (appState === 'active') await this.start('App entered foreground');
415+
if (starting) await this.start('App entered foreground');
415416
else await this._stop('App entered background');
416417
} catch (e) {
417418
// If anything goes wrong within .start() or ._stop() calls, those methods
@@ -425,12 +426,18 @@ class StaticServer {
425426
// it as unhandled, which is confusing when the error has been handled
426427
// within the listener).
427428
//
428-
// However, if no listeners are connected, we re-throw the error to allow
429+
// However, if no listeners are connected, we throw an error to allow
429430
// the instrumentation, if any, to detect and report it as unhandled.
430431
//
431432
// In either case this very function is used internally, thus no way for
432433
// the library consumer to directly handle its possible rejections.
433-
if (!this._stateChangeEmitter.hasListeners) throw e;
434+
if (!this._stateChangeEmitter.hasListeners) {
435+
throw Error(
436+
starting
437+
? 'Server auto-start on the app going into foreground failed'
438+
: 'Server auto-stop on the app going into background failed',
439+
);
440+
}
434441
}
435442
}
436443
}

0 commit comments

Comments
 (0)