Skip to content

Commit b560c8e

Browse files
committed
Simplify error handling
1 parent f33bee1 commit b560c8e

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

packages/messaging/src/api.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ export function getMessagingInWindow(app: FirebaseApp = getApp()): Messaging {
5151
// special handling.
5252
isWindowSupported()
5353
.then(isSupported => {
54+
// If `isWindowSupported()` resolved, but returned false.
5455
if (!isSupported) {
5556
throw ERROR_FACTORY.create(ErrorCode.UNSUPPORTED_BROWSER);
5657
}
57-
})
58-
.catch((e: Error) => {
59-
if (e.message.includes(ErrorCode.UNSUPPORTED_BROWSER)) {
60-
throw e;
61-
}
58+
}, _ => {
59+
// If `isWindowSupported()` rejected.
6260
throw ERROR_FACTORY.create(ErrorCode.INDEXED_DB_UNSUPPORTED);
6361
});
6462
return _getProvider(getModularInstance(app), 'messaging').getImmediate();
@@ -77,17 +75,15 @@ export function getMessagingInSw(app: FirebaseApp = getApp()): Messaging {
7775
// developer's information. Developers can then choose to import and call `isSupported` for
7876
// special handling.
7977
isSwSupported()
80-
.then(isSupported => {
81-
if (!isSupported) {
82-
throw ERROR_FACTORY.create(ErrorCode.UNSUPPORTED_BROWSER);
83-
}
84-
})
85-
.catch((e: Error) => {
86-
if (e.message.includes(ErrorCode.UNSUPPORTED_BROWSER)) {
87-
throw e;
88-
}
89-
throw ERROR_FACTORY.create(ErrorCode.INDEXED_DB_UNSUPPORTED);
90-
});
78+
.then(isSupported => {
79+
// If `isSwSupported()` resolved, but returned false.
80+
if (!isSupported) {
81+
throw ERROR_FACTORY.create(ErrorCode.UNSUPPORTED_BROWSER);
82+
}
83+
}, _ => {
84+
// If `isSwSupported()` rejected.
85+
throw ERROR_FACTORY.create(ErrorCode.INDEXED_DB_UNSUPPORTED);
86+
});
9187
return _getProvider(getModularInstance(app), 'messaging-sw').getImmediate();
9288
}
9389

0 commit comments

Comments
 (0)