diff --git a/src/common.ts b/src/common.ts index e7c75df9..17572649 100644 --- a/src/common.ts +++ b/src/common.ts @@ -39,16 +39,22 @@ export const GAXIOS_ERROR_SYMBOL = Symbol.for(`${pkg.name}-gaxios-error`); /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ export class GaxiosError extends Error { /** - * An Error code. - * See {@link https://nodejs.org/api/errors.html#errorcode error.code} + * An error code. + * Can be a system error code, DOMException error name, or any error's 'code' property where it is a `string`. + * + * @see {@link https://nodejs.org/api/errors.html#errorcode error.code} + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#error_names DOMException#error_names} * * @example * 'ECONNRESET' + * + * @example + * 'TimeoutError' */ code?: string; /** * An HTTP Status code. - * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/status Response: status property} + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/status Response#status} * * @example * 500 diff --git a/src/gaxios.ts b/src/gaxios.ts index 22770fe5..dba42b9d 100644 --- a/src/gaxios.ts +++ b/src/gaxios.ts @@ -395,17 +395,6 @@ export class Gaxios { ) as {} as ReadableStream; } else if (shouldDirectlyPassData) { opts.body = opts.data as BodyInit; - - /** - * Used for backwards-compatibility. - * - * @deprecated we shouldn't infer Buffers as JSON - */ - if ('Buffer' in globalThis && Buffer.isBuffer(opts.data)) { - if (!preparedHeaders.has('content-type')) { - preparedHeaders.set('content-type', 'application/json'); - } - } } else if (typeof opts.data === 'object') { if ( preparedHeaders.get('Content-Type') === diff --git a/test/test.getch.ts b/test/test.getch.ts index c42f1dbf..8b987f9a 100644 --- a/test/test.getch.ts +++ b/test/test.getch.ts @@ -1158,20 +1158,18 @@ describe('🍂 defaults & instances', () => { assert.deepStrictEqual(res.data, {}); }); - it('should set content-type to application/json by default, for buffer', async () => { - const pkg = fs.readFileSync('./package.json'); - const pkgJson = JSON.parse(pkg.toString('utf8')); + it('should not set a default content-type for buffers', async () => { + const jsonLike = '{}'; + const data = Buffer.from(jsonLike); const scope = nock(url) - .matchHeader('content-type', 'application/json') - .post('/', pkgJson) - .reply(200, {}); - const res = await request({ - url, - method: 'POST', - data: pkg, - }); + // no content type should be present + .matchHeader('content-type', v => v === undefined) + .post('/', jsonLike) + .reply(204); + + const res = await request({url, method: 'POST', data}); scope.done(); - assert.deepStrictEqual(res.data, {}); + assert.equal(res.status, 204); }); describe('mtls', () => {