In general callbacks are expected to return error first.
There’s really only two rules for defining an error-first callback:
- The first argument of the callback is reserved for an error object. If an error occurred, it will be returned by the first err argument.
- The second argument of the callback is reserved for any successful response data. If no error occurred, err will be set to null and any successful data will be returned in the second argument.
Current:
try {
var res = JSON.parse(body);
callback(res, false);
} catch (e) {
callback(false, { error: body } );
}
In general callbacks are expected to return error first.
There’s really only two rules for defining an error-first callback:
Current: