Skip to content

Commit

Permalink
fix: allow API redirect responses (twilio#101)
Browse files Browse the repository at this point in the history
Fetching a BulkExport for a single day returns a `307` with the AWS URL for the file. With this change, the URL will now be included in the CLI response.

https://www.twilio.com/docs/usage/bulkexport/day?code-sample=code-fetch-a-single-file-for-an-exported-day
  • Loading branch information
childish-sambino committed Jul 30, 2020
1 parent c5f654e commit 9b766d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/cli-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CliRequestClient {
this.logger.debug(`response.statusCode: ${response.status}`);
this.logger.debug(`response.headers: ${JSON.stringify(response.headers)}`);

if (response.status < 200 || response.status >= 300) {
if (response.status < 200 || response.status >= 400) {
const parsed = response.data;
throw new TwilioCliError(
`Error code ${parsed.code} from Twilio: ${parsed.message}. See ${parsed.more_info} for more info.`,
Expand Down
14 changes: 14 additions & 0 deletions test/services/twilio-api/twilio-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ describe('services', () => {
expect(response).to.eql({ status: 'queued' });
});

test
.nock('https://api.twilio.com', (api) => {
api.get(`/2010-04-01/Accounts/${accountSid}/Messages.json`).reply(307, '{"redirect_to": "some_other_place"}');
})
.it('handles redirects', async () => {
const response = await apiClient.fetch({
domain: 'api',
path: '/2010-04-01/Accounts/{AccountSid}/Messages.json',
});

// eslint-disable-next-line camelcase
expect(response).to.eql({ redirect_to: 'some_other_place' });
});

test
.nock('https://api.twilio.com', (api) => {
api
Expand Down

0 comments on commit 9b766d7

Please sign in to comment.