Skip to content
This repository has been archived by the owner on Feb 13, 2018. It is now read-only.

Bug fix: callbacks being called twice when JSON.parse() throws an exception #37

Merged
merged 1 commit into from
Jun 19, 2016

Conversation

netoabel
Copy link
Contributor

In:

try {
    callback(null, JSON.parse(data));
} catch (e) {
    callback(e, data, response);
}

Both callbacks are called, because when JSON.parse() throws the exception, in try, the callback method was already called.

So I changed it to:

try {
    var parsedBody = JSON.parse(body);
} catch (e) {
    callback(e, body, response);
}
callback(null, parsedBody, response);

@reneraab reneraab merged commit cbc3174 into reneraab:master Jun 19, 2016
reneraab added a commit that referenced this pull request Jun 19, 2016
* Fix bug: callbacks being called twice when JSON.parse() throws an error (@netoabel) #37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants