-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
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]; |
There was a problem hiding this comment.
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.
@hermanliang updated the pull request. |
@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); |
There was a problem hiding this comment.
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!
@hermanliang updated the pull request. |
1 similar comment
@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 ''; |
There was a problem hiding this comment.
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 ''
No description provided.