Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

RestJS doesn't return errors #20

Open
quy-le opened this issue Aug 3, 2015 · 0 comments
Open

RestJS doesn't return errors #20

quy-le opened this issue Aug 3, 2015 · 0 comments

Comments

@quy-le
Copy link
Contributor

quy-le commented Aug 3, 2015

The RestJS client doesn't return certain errors. For example, socket hang ups [ECONNRESET].

Check out the file restjs/tools/rest.js

In the Request.prototype.request, there's an event req.on('error', finish);. In the finish function, it never actually calls the callback if there is an error. For this case, isDone was false and err was a string.

    function finish(err, res) {
      if (isDone) return; //This would only happen if an error occurs AFTER the res has ended...doubtful that would ever happen.

      if (err) {
        callbackArgs[0] = err; //If there's an error and no res, collect it and keep waiting until the 'end' event
      } else {
        isDone = true;
        callbackArgs[1] = res;

        if (!callbackArgs[0] && middleware.length) { //If there isn't already an error and there is middleware, run them
          async.eachSeries(
            middleware,
            function(middlewareItem, fn) {
              middlewareItem(res, fn);
            },
            function(err) {
              if (err) callbackArgs[0] = err;
              callback.apply(null, callbackArgs); //Pass both the err and res to the callback, because often times the body will be just fine despite errors
            }
          );
        } else {
          callback.apply(null, callbackArgs); //Pass both the err and res to the callback, because often times the body will be just fine despite errors
        }
      }
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant