diff --git a/src/notification/extract.js b/src/notification/extract.js index bf074b2c455..631ac6cd9dd 100644 --- a/src/notification/extract.js +++ b/src/notification/extract.js @@ -99,10 +99,18 @@ class ApnsMsgValidationError extends Error { // @returns A `Notification` on success, `undefined` on suppressible failure. // @throws An ApnsMsgValidationError on unexpected failure. // -export const fromAPNsImpl = (rawData: JSONableDict): Notification | void => { +export const fromAPNsImpl = (rawData: ?JSONableDict): Notification | void => { /** Helper function: fail. */ const err = (style: string) => - new ApnsMsgValidationError(`Received ${style} APNs notification`, { data: rawData }); + new ApnsMsgValidationError(`Received ${style} APNs notification`, { + // an `undefined` value would make `extras` not JSONable, but we will + // want to know if the value is undefined + data: rawData === undefined ? '__undefined__' : rawData, + }); + + if (rawData == null) { + throw err('nullish'); + } // APNs messages are JSON dictionaries. The `aps` entry of this dictionary is // required, with a structure defined by Apple; all other entries are @@ -208,7 +216,7 @@ export const fromAPNsImpl = (rawData: JSONableDict): Notification | void => { * * @returns A `Notification` on success; `undefined` on failure. */ -export const fromAPNs = (data: JSONableDict): Notification | void => { +export const fromAPNs = (data: ?JSONableDict): Notification | void => { try { return fromAPNsImpl(data); } catch (err) { diff --git a/src/notification/index.js b/src/notification/index.js index 3aee46b4cad..096f0af2ed2 100644 --- a/src/notification/index.js +++ b/src/notification/index.js @@ -135,9 +135,6 @@ const readInitialNotification = async (): Promise => { // present, it must be a JSONable dictionary. It's giving us the // notification data, which was passed over APNs as JSON. const data: ?JSONableDict = notification.getData(); - if (!data) { - return null; - } return fromAPNs(data) || null; }; @@ -265,9 +262,6 @@ export class NotificationListener { // if present, it must be a JSONable dictionary. It's giving us the // notification data, which was passed over APNs as JSON. const data: ?JSONableDict = notification.getData(); - if (!data) { - return; - } const dataFromAPNs: Notification | void = fromAPNs(data); if (!dataFromAPNs) { return;