@injectivelabs/utils
Advanced tools
Comparing version 1.0.51 to 1.0.52
@@ -14,3 +14,7 @@ "use strict"; | ||
this.config = {}; | ||
this.client = axios_1.default.create(Object.assign({ baseURL: endpoint, timeout: 15000 }, options)); | ||
this.client = axios_1.default.create({ | ||
baseURL: endpoint, | ||
timeout: 15000, | ||
...options, | ||
}); | ||
this.config = {}; | ||
@@ -23,3 +27,3 @@ } | ||
get(endpoint, params = {}) { | ||
return this.client.get(endpoint, Object.assign({ params }, this.config)); | ||
return this.client.get(endpoint, { params, ...this.config }); | ||
} | ||
@@ -30,3 +34,3 @@ post(endpoint, data = {}) { | ||
delete(endpoint, params = {}) { | ||
return this.client.delete(endpoint, Object.assign({ params }, this.config)); | ||
return this.client.delete(endpoint, { params, ...this.config }); | ||
} | ||
@@ -33,0 +37,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -38,59 +29,55 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
get(endpoint, params = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield this.client.get(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
method: exceptions_1.HttpRequestMethod.Get, | ||
}); | ||
} | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
async get(endpoint, params = {}) { | ||
try { | ||
return await this.client.get(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
method: exceptions_1.HttpRequestMethod.Get, | ||
}); | ||
} | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
contextModule: exceptions_1.HttpRequestMethod.Get, | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
method: exceptions_1.HttpRequestMethod.Get, | ||
}); | ||
} | ||
}); | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
contextModule: exceptions_1.HttpRequestMethod.Get, | ||
}); | ||
} | ||
} | ||
post(endpoint, params = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield this.client.post(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
method: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
} | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
contextModule: exceptions_1.HttpRequestMethod.Post, | ||
async post(endpoint, params = {}) { | ||
try { | ||
return await this.client.post(endpoint, params); | ||
} | ||
catch (e) { | ||
const error = e; | ||
if (axios_1.default.isAxiosError(error)) { | ||
if (error.code === 'ECONNABORTED') { | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG, | ||
method: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
} | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
const message = getErrorMessage(error, endpoint); | ||
throw new exceptions_1.HttpRequestException(new Error(message), { | ||
code: error.response | ||
? error.response.status | ||
: http_status_codes_1.StatusCodes.BAD_REQUEST, | ||
contextModule: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
} | ||
}); | ||
throw new exceptions_1.HttpRequestException(new Error(error.message), { | ||
code: exceptions_1.UnspecifiedErrorCode, | ||
contextModule: exceptions_1.HttpRequestMethod.Post, | ||
}); | ||
} | ||
} | ||
@@ -97,0 +84,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
const trailingZeros = 13 - timestamp.toString().length; | ||
return timestampInBigNumber.times(Math.pow(10, trailingZeros)).toNumber(); | ||
return timestampInBigNumber.times(10 ** trailingZeros).toNumber(); | ||
} | ||
@@ -18,0 +18,0 @@ return timestampInBigNumber.toNumber(); |
{ | ||
"name": "@injectivelabs/utils", | ||
"description": "List of utils and helper functions that can be reused throughout Injective's projects.", | ||
"version": "1.0.51", | ||
"version": "1.0.52", | ||
"author": { | ||
@@ -34,4 +34,4 @@ "name": "Bojan Angjelkoski", | ||
"dependencies": { | ||
"@injectivelabs/exceptions": "^1.0.35", | ||
"@injectivelabs/ts-types": "^1.0.20", | ||
"@injectivelabs/exceptions": "^1.0.36", | ||
"@injectivelabs/ts-types": "^1.0.21", | ||
"axios": "^0.21.1", | ||
@@ -45,3 +45,3 @@ "bignumber.js": "^9.0.1", | ||
}, | ||
"gitHead": "b4f63274d43081ef8349c36199813932168a5f27" | ||
"gitHead": "9c5c63534dd63a09be137644b4ca41fbdc8c5781" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
68435
721