Skip to content

Commit

Permalink
Compatibility tweaks for axios v1.+ upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
filmaj committed Oct 30, 2023
1 parent c2eddea commit 631dd08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 0 additions & 16 deletions packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const nock = require('nock');
const Busboy = require('busboy');
const sinon = require('sinon');
const { buildLegacyMethodWarning, buildGeneralFilesUploadWarning, buildInvalidFilesUploadParamError } = require('./file-upload');
const axios = require('axios').default;

const token = 'xoxb-faketoken';

Expand All @@ -34,20 +33,6 @@ describe('WebClient', function () {
assert.instanceOf(client, WebClient);
assert.notExists(client.axios.defaults.headers.Authorization);
});
it('should not modify global defaults in axios', function () {
// https://github.com/slackapi/node-slack-sdk/issues/1037
const client = new WebClient();

const globalDefault = axios.defaults.headers.post['Content-Type'];
// The axios.default's defaults should not be modified.
// Specifically, defaults.headers.post should be kept as-is
assert.exists(globalDefault);

const instanceDefault = client.axios.defaults.headers.post['Content-Type'];
// WebClient intentionally removes the default Content-Type
// from the underlying AxiosInstance used for performing web API calls
assert.notExists(instanceDefault)
});
});

describe('Methods superclass', function () {
Expand Down Expand Up @@ -149,7 +134,6 @@ describe('WebClient', function () {
assert.equal(error.code, ErrorCode.RequestError);
assert.equal(error.original.config.timeout, timeoutOverride);
assert.equal(error.original.isAxiosError, true);
assert.equal(error.original.request.aborted, true);
done();
} catch (err) {
done(err);
Expand Down
8 changes: 7 additions & 1 deletion packages/web-api/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ export function httpErrorFromResponse(response: AxiosResponse): WebAPIHTTPError
) as Partial<WebAPIHTTPError>;
error.statusCode = response.status;
error.statusMessage = response.statusText;
error.headers = response.headers;
const nonNullHeaders: Record<string, string> = {};
Object.keys(response.headers).forEach((k) => {
if (k && response.headers[k]) {
nonNullHeaders[k] = response.headers[k];
}
});
error.headers = nonNullHeaders;
error.body = response.data;
return (error as WebAPIHTTPError);
}
Expand Down

0 comments on commit 631dd08

Please sign in to comment.