Skip to content

Past Pushes: fix error if alert field is not exist in payload #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/dashboard/Push/PushIndex.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ let getPushName = (pushData) => {
<strong>{title}</strong>
);
} else {
let payload = pushData[PushConstants.PAYLOAD_FIELD];
let payload = pushData[PushConstants.PAYLOAD_FIELD] || '';
try {
payload = JSON.parse(payload);
} catch(e) { }
if (payload) {
if (typeof payload === 'object') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check type of payload

if (typeof payload.alert === 'string') {
return payload.alert;
}
return payload.alert ? JSON.stringify(payload.alert) : payload;
return payload.alert ? JSON.stringify(payload.alert) : JSON.stringify(payload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! One nit is that when the payload is empty string JSON.stringify('') results in a double string outputted. We'll only need stringify if payload is an object. Once you've added that check its go to merge. Thanks!

} else {
return '';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If payload is not an object
return ''

}
}
}
Expand Down