Skip to content

Proposed: Return response from request #24

Description

@ryanjones

I need to gain access to the link header from my request that I've sent to github. I've done a quick fix for this by changing this chunk of code in Github.prototype.request:

  if ((200 <= (_ref2 = res.statusCode) && _ref2 < 300)) {
          return cb(responseData);
        } else {
          return _this._errorHandler({
            statusCode: res.statusCode,
            body: body,
            error: responseData.message
          });
        }

to this (passing back the response with the responseData):

  if ((200 <= (_ref2 = res.statusCode) && _ref2 < 300)) {
          return cb(responseData, res);
        } else {
          return _this._errorHandler({
            statusCode: res.statusCode,
            body: body,
            error: responseData.message
          });
        }

This allows me to do this (coffee):

    get_github_issues = (page) ->
      promise = new RSVP.Promise((resolve, reject) ->
        url = "#{url_api_base}/orgs/#{org_name}/issues?filter=all&page=#{page}&per_page=100&sort=created"
        github.get url, (issues, res) ->
          console.log res["headers"]["link"]
          resolve issues
        )
      promise

I don't think would cause any regression as it would be an optional parameter in the callback.

Let me know if this is something you'd considering merging and I can create a PR for it. On that note, if you have a better way to grab the headers I'm all ears!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions