Comparing version 1.3.0 to 1.4.0
@@ -23,2 +23,7 @@ import { Agent } from 'https'; | ||
export interface GaxiosOptions { | ||
/** | ||
* Optional method to override making the actual HTTP request. Useful | ||
* for writing tests. | ||
*/ | ||
adapter?: <T = any>(options: GaxiosOptions) => GaxiosPromise<T>; | ||
url?: string; | ||
@@ -25,0 +30,0 @@ baseUrl?: string; |
@@ -60,9 +60,15 @@ "use strict"; | ||
try { | ||
const res = yield node_fetch_1.default(opts.url, opts); | ||
const data = yield this.getResponseData(opts, res); | ||
const translatedResponse = this.translateResponse(opts, res, data); | ||
if (!opts.validateStatus(res.status)) { | ||
throw new common_1.GaxiosError(`Request failed with status code ${res.status}`, opts, translatedResponse); | ||
let translatedResponse; | ||
if (opts.adapter) { | ||
translatedResponse = yield opts.adapter(opts); | ||
} | ||
return this.translateResponse(opts, res, data); | ||
else { | ||
const res = yield node_fetch_1.default(opts.url, opts); | ||
const data = yield this.getResponseData(opts, res); | ||
translatedResponse = this.translateResponse(opts, res, data); | ||
} | ||
if (!opts.validateStatus(translatedResponse.status)) { | ||
throw new common_1.GaxiosError(`Request failed with status code ${translatedResponse.status}`, opts, translatedResponse); | ||
} | ||
return translatedResponse; | ||
} | ||
@@ -69,0 +75,0 @@ catch (e) { |
{ | ||
"name": "gaxios", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A simple common HTTP client specifically for Google APIs and services.", | ||
@@ -5,0 +5,0 @@ "main": "build/src/index.js", |
@@ -79,2 +79,10 @@ # gaxios | ||
// Optional method to override making the actual HTTP request. Useful | ||
// for writing tests. | ||
adapter?: (options) => { | ||
return { | ||
data: 'your data' | ||
} | ||
}; | ||
// The expected return type of the request. Options are: | ||
@@ -81,0 +89,0 @@ // json | stream | blob | arraybuffer | text |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46932
537
135