Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponseError fails when request is raw #315

Closed
cabarnes opened this issue Feb 4, 2021 · 3 comments · Fixed by #320
Closed

ResponseError fails when request is raw #315

cabarnes opened this issue Feb 4, 2021 · 3 comments · Fixed by #320
Labels
bug Something isn't working core

Comments

@cabarnes
Copy link

cabarnes commented Feb 4, 2021

Bug Description

If the request is set to raw, the prepareRawResponse function sets the content property of the response to throw an Error: https://github.com/zapier/zapier-platform/blob/master/packages/core/src/http-middlewares/after/prepare-response.js#L18

When the ResponseError object is created, it accesses response.content causing that error to be thrown:

Error: You passed {raw: true} in request() - the response.content property is not available! Try response.body.pipe() for streaming, response.buffer() for a buffer, or response.text() for string.
    at Response.get (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/http-middlewares/after/prepare-response.js:20:13)
    at new ResponseError (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/errors.js:28:27)
    at throwForStatus (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/http-middlewares/after/throw-for-status.js:11:11)
    at Object.<anonymous> (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:80:37)
    at bound (domain.js:427:14)
    at Object.runBound (domain.js:440:12)
    at Object.tryCatcher (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (:censored:9:d1ba0cf2aa:/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:461:21)
    at process.topLevelDomainCallback (domain.js:138:15)
    at process.callbackTrampoline (internal/async_hooks.js:124:14)

This means that if the error is a 401, the refresh authentication does not happen. It also makes it difficult to even know what the error was from the request.

Reproduction Steps

  1. Create a raw request:
z.request({
      url: `https://example.com/file.txt`,
      raw: true,
    })
  1. On the server, set the access token expiration to a time in the past
  2. Execute the request and the 401 response should cause the error to occur.

Version Info

  • Version info:
    • CLI version: 10.1.2
    • Node.js version: v12.20.1
    • OS info: linux-x64
    • zapier-platform-core dependency: 10.1.2
@zapzap
Copy link

zapzap commented Feb 5, 2021

This issue has been copied into our private issue tracker (as PDE-1977). Thanks for the report! We'll update this as we learn more.

@xavdid
Copy link
Contributor

xavdid commented Feb 5, 2021

Thanks for the report! We'll take a look.

@xavdid xavdid added bug Something isn't working core labels Feb 5, 2021
@xavdid
Copy link
Contributor

xavdid commented Feb 8, 2021

This is fixed as part of #320. The issue will close once that's merged, but the code won't deploy until our next release.

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
3 participants