Skip to content

Commit

Permalink
Check for callback prior to firing it
Browse files Browse the repository at this point in the history
Prevents an error when client is used without a callback.
  • Loading branch information
drewwells committed Mar 4, 2014
1 parent 6933e50 commit fbca445
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/clients/json_client.js
Expand Up @@ -81,7 +81,8 @@ JsonClient.prototype.parse = function parse(req, callback) {
if (err)
err.body = obj;

callback((err || null), req2, res, obj);
if (callback)
callback((err || null), req2, res, obj);
}

return (this._super.parse.call(this, req, parseResponse));
Expand Down

4 comments on commit fbca445

@gergelyke
Copy link

Choose a reason for hiding this comment

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

What is the use-case for it? In my opinion it makes no sense to use it without the callback

@drewwells
Copy link
Owner Author

Choose a reason for hiding this comment

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

It makes the API more resilient to developer errors. Also many times you want to make a request without caring about the response. For example, health checks, pingbacks, push requests to services (I was doing a data push to Geckoboard when encountering this).

@gergelyke
Copy link

Choose a reason for hiding this comment

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

But it also hide errors - if I forget to pass a callback in, I want the app to break, not to hide it. Also, if you are about to make healtchecks, pingbacks, you need the callback, that's the only way to check for status codes/errors

@drewwells
Copy link
Owner Author

@drewwells drewwells commented on fbca445 Mar 4, 2014 via email

Choose a reason for hiding this comment

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

Please sign in to comment.