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

Conversation

hermanliang
Copy link
Contributor

No description provided.

@facebook-github-bot
Copy link

By analyzing the blame information on this pull request, we identified @drew-gross, @JeremyPlease and @durunvo to be potential reviewers.

@@ -141,15 +141,11 @@ let getPushName = (pushData) => {
);
} else {
let payload = pushData[PushConstants.PAYLOAD_FIELD];
Copy link
Contributor

@peterdotjs peterdotjs Jun 24, 2016

Choose a reason for hiding this comment

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

You could just change this line to: let payload = pushData[PushConstants.PAYLOAD_FIELD] || '';

This should achieve what you are looking for. While keeping the existing alert type checks in place.

@ghost
Copy link

ghost commented Jun 24, 2016

@hermanliang updated the pull request.

@ghost
Copy link

ghost commented Jun 24, 2016

@hermanliang updated the pull request.

try {
payload = JSON.parse(payload);
} catch(e) { }
if (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!

@ghost
Copy link

ghost commented Jun 25, 2016

@hermanliang updated the pull request.

1 similar comment
@ghost
Copy link

ghost commented Jun 25, 2016

@hermanliang updated the pull request.

return payload.alert ? JSON.stringify(payload.alert) : payload;
return payload.alert ? JSON.stringify(payload.alert) : JSON.stringify(payload);
} 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 ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants