in typescript/src/pubsub/google-common.ts [75:104]
export function parsePayload(
body: Option<string>,
): Error | SubscriptionNotification | Ignorable {
try {
const rawNotification = Buffer.from(
JSON.parse(body ?? '').message.data,
'base64',
);
const parseResult = DeveloperNotificationSchema.safeParse(
JSON.parse(rawNotification.toString()),
);
if (!parseResult.success) {
return new Error(`HTTP Payload body parse error: ${parseResult.error}`);
}
const data = parseResult.data;
if (isSubscriptionNotification(data)) {
return data;
}
return new Ignorable(
`Notification is not a subscription notification. Notification was: ${JSON.stringify(
data,
)}`,
);
} catch (e) {
console.log('Error during the parsing of the HTTP Payload body: ' + e);
return e as Error;
}
}