@elastic.io/component-commons-library
Advanced tools
Comparing version 3.0.3-dev.15 to 3.0.3-dev.16
{ | ||
"name": "@elastic.io/component-commons-library", | ||
"version": "3.0.3-dev.14", | ||
"version": "3.0.3-dev.15", | ||
"description": "Library for most common component development cases", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -19,3 +19,2 @@ "use strict"; | ||
const notFoundBody = 'Not found'; | ||
const errNotFound = `Got error "unknown", status - "${notFoundStatusCode}", body: "${notFoundBody}"`; | ||
const secretId = 'secretId'; | ||
@@ -89,3 +88,3 @@ const cfg = { | ||
.catch((e) => { | ||
expect(e.message).to.be.equal(errNotFound); | ||
expect(e.message).to.be.equal('Request failed with status code 404'); | ||
}); | ||
@@ -92,0 +91,0 @@ }); |
@@ -12,4 +12,3 @@ import { PlatformApiLogicClient } from '../platformApi/PlatformApiLogicClient'; | ||
protected addAuthenticationToRequestOptions(requestOptions: any): Promise<void>; | ||
protected handleRestResponse(response: any): any; | ||
makeRequest(options: any): Promise<any>; | ||
} |
@@ -43,9 +43,2 @@ "use strict"; | ||
} | ||
handleRestResponse(response) { | ||
if (response.status >= 400) { | ||
throw new Error((0, externalApi_1.getErrMsg)(response)); | ||
} | ||
this.logger.debug(`Response status: ${response.status}`); | ||
return response; | ||
} | ||
// options expects the following sub-variables: | ||
@@ -59,3 +52,3 @@ // url: Url to call | ||
async makeRequest(options) { | ||
var _a; | ||
var _a, _b; | ||
const { url, method, body, headers = {}, urlIsSegment = true, } = options; | ||
@@ -79,11 +72,11 @@ const urlToCall = urlIsSegment | ||
const response = await externalApi_1.axiosReqWithRetryOnServerError.call(this, requestOptions, this.axiosInst); | ||
return this.handleRestResponse(response); | ||
return response; | ||
} | ||
catch (err) { | ||
this.logger.error((0, externalApi_1.getErrMsg)(err.response)); | ||
error = err; | ||
if (((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) !== 401) { | ||
return this.handleRestResponse(err.response); | ||
if (((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) < 500 && ((_b = err.response) === null || _b === void 0 ? void 0 : _b.status) !== 401) { | ||
throw err; | ||
} | ||
this.logger.error(`URL: "${requestOptions.url}", method: ${requestOptions.method}, Error message: "${err.message}"`); | ||
this.logger.info(`Request failed, retrying(${1 + currentRetry})`); | ||
this.logger.info(`Request failed, faceless retrying(${1 + currentRetry})`); | ||
this.accessToken = null; | ||
@@ -90,0 +83,0 @@ currentRetry++; |
@@ -71,2 +71,3 @@ "use strict"; | ||
catch (err) { | ||
this.logger.error((0, exports.getErrMsg)(err.response)); | ||
error = err; | ||
@@ -77,3 +78,2 @@ if (((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) < 500) { | ||
this.logger.info(`URL: "${options.url}", method: ${options.method}, Error message: "${err.message}"`); | ||
this.logger.error((0, exports.getErrMsg)(err.response)); | ||
this.logger.info(`Request failed, retrying(${1 + currentRetry})`); | ||
@@ -80,0 +80,0 @@ await (0, exports.exponentialSleep)(currentRetry); |
{ | ||
"name": "@elastic.io/component-commons-library", | ||
"version": "3.0.3-dev.15", | ||
"version": "3.0.3-dev.16", | ||
"description": "Library for most common component development cases", | ||
@@ -67,2 +67,2 @@ "author": { | ||
"license": "Apache-2.0" | ||
} | ||
} |
260608
5724