Socket
Socket
Sign inDemoInstall

gaxios

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gaxios - npm Package Compare versions

Comparing version 5.1.3 to 6.0.0

21

build/src/common.d.ts
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Agent } from 'http';
import { URL } from 'url';
export declare class GaxiosError<T = any> extends Error {
error?: Error | NodeJS.ErrnoException | undefined;
/**
* An Error code.
* See {@link https://nodejs.org/api/errors.html#errorcode error.code}
*
* @example
* 'ECONNRESET'
*/
code?: string;
response?: GaxiosResponse<T>;
config: GaxiosOptions;
constructor(message: string, options: GaxiosOptions, response: GaxiosResponse<T>);
/**
* An HTTP Status code.
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/Response/status Response: status property}
*
* @example
* 500
*/
status: number;
constructor(message: string, options: GaxiosOptions, response: GaxiosResponse<T>, error?: Error | NodeJS.ErrnoException | undefined);
}

@@ -60,3 +77,3 @@ export interface Headers {

onUploadProgress?: (progressEvent: any) => void;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text' | 'stream';
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text' | 'stream' | 'unknown';
agent?: Agent | ((parsedUrl: URL) => Agent);

@@ -63,0 +80,0 @@ validateStatus?: (status: number) => boolean;

8

build/src/common.js

@@ -18,8 +18,12 @@ "use strict";

class GaxiosError extends Error {
constructor(message, options, response) {
constructor(message, options, response, error) {
super(message);
this.error = error;
this.response = response;
this.config = options;
this.response.data = translateData(options.responseType, response.data);
this.code = response.status.toString();
if (error && 'code' in error && error.code) {
this.code = error.code;
}
this.status = response.status;
}

@@ -26,0 +30,0 @@ }

@@ -44,2 +44,8 @@ /// <reference types="node" />

private translateResponse;
/**
* Attempts to parse a response by looking at the Content-Type header.
* @param {FetchResponse} response the HTTP response.
* @returns {Promise<any>} a promise that resolves to the response data.
*/
private getResponseDataFromContentType;
}

@@ -175,3 +175,3 @@ "use strict";

default:
return res.text();
return this.getResponseDataFromContentType(res);
}

@@ -245,3 +245,3 @@ }

opts.validateStatus = opts.validateStatus || this.validateStatus;
opts.responseType = opts.responseType || 'json';
opts.responseType = opts.responseType || 'unknown';
if (!opts.headers['Accept'] && opts.responseType === 'json') {

@@ -321,4 +321,28 @@ opts.headers['Accept'] = 'application/json';

}
/**
* Attempts to parse a response by looking at the Content-Type header.
* @param {FetchResponse} response the HTTP response.
* @returns {Promise<any>} a promise that resolves to the response data.
*/
getResponseDataFromContentType(response) {
let contentType = response.headers.get('Content-Type');
if (contentType === null) {
// Maintain existing functionality by calling text()
return response.text();
}
contentType = contentType.toLowerCase();
if (contentType.includes('application/json')) {
return response.json();
}
else if (contentType.includes('text/plain') ||
contentType.includes('text/html')) {
return response.text();
}
else {
// If the content type is something not easily handled, just return the raw data (blob)
return response.blob();
}
}
}
exports.Gaxios = Gaxios;
//# sourceMappingURL=gaxios.js.map
# Changelog
## [6.0.0](https://github.com/googleapis/gaxios/compare/v5.1.3...v6.0.0) (2023-07-12)
### ⚠ BREAKING CHANGES
* add status as a number to GaxiosError, change code to error code as a string ([#552](https://github.com/googleapis/gaxios/issues/552))
* migrate to Node 14 ([#548](https://github.com/googleapis/gaxios/issues/548))
* examine response content-type if no contentType is set ([#535](https://github.com/googleapis/gaxios/issues/535))
### Bug Fixes
* Add status as a number to GaxiosError, change code to error code as a string ([#552](https://github.com/googleapis/gaxios/issues/552)) ([88ba2e9](https://github.com/googleapis/gaxios/commit/88ba2e99e32b66d84725c9ea9ad95152bd1dc653))
* Examine response content-type if no contentType is set ([#535](https://github.com/googleapis/gaxios/issues/535)) ([cd8ca7b](https://github.com/googleapis/gaxios/commit/cd8ca7b209f0ba932082a80ace8fec608a71facf))
### Miscellaneous Chores
* Migrate to Node 14 ([#548](https://github.com/googleapis/gaxios/issues/548)) ([b9b26eb](https://github.com/googleapis/gaxios/commit/b9b26eb2c4af35633efd91770aa24c4b5d9019b4))
## [5.1.3](https://github.com/googleapis/gaxios/compare/v5.1.2...v5.1.3) (2023-07-05)

@@ -4,0 +23,0 @@

{
"name": "gaxios",
"version": "5.1.3",
"version": "6.0.0",
"description": "A simple common HTTP client specifically for Google APIs and services.",

@@ -35,3 +35,3 @@ "main": "build/src/index.js",

"engines": {
"node": ">=12"
"node": ">=14"
},

@@ -63,3 +63,3 @@ "author": "Google, LLC",

"form-data": "^4.0.0",
"gts": "^3.1.0",
"gts": "^3.1.1",
"is-docker": "^2.0.0",

@@ -86,3 +86,3 @@ "karma": "^6.0.0",

"ts-loader": "^8.0.0",
"typescript": "^4.6.3",
"typescript": "^5.1.6",
"uuid": "^9.0.0",

@@ -89,0 +89,0 @@ "webpack": "^5.35.0",

@@ -104,5 +104,5 @@ # gaxios

// The expected return type of the request. Options are:
// json | stream | blob | arraybuffer | text
// Defaults to `json`.
responseType: 'json',
// json | stream | blob | arraybuffer | text | unknown
// Defaults to `unknown`.
responseType: 'unknown',

@@ -109,0 +109,0 @@ // The node.js http agent to use for the request.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc