@gnosis.pm/safe-react-gateway-sdk
Advanced tools
Comparing version 3.5.1 to 3.5.2
@@ -17,2 +17,6 @@ "use strict"; | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
const isErrorResponse = (data) => { | ||
const isObject = typeof data === 'object' && data !== null; | ||
return isObject && 'code' in data && 'message' in data; | ||
}; | ||
function replaceParam(str, key, value) { | ||
@@ -54,12 +58,13 @@ return str.replace(new RegExp(`\\{${key}\\}`, 'g'), value); | ||
const resp = yield (0, cross_fetch_1.default)(url, options); | ||
const json = yield resp.json(); | ||
let json; | ||
try { | ||
json = yield resp.json(); | ||
} | ||
catch (_a) { | ||
if (resp.headers && resp.headers.get('content-length') !== '0') { | ||
throw new Error(`Invalid response content: ${resp.statusText}`); | ||
} | ||
} | ||
if (!resp.ok) { | ||
let errTxt = ''; | ||
try { | ||
const err = json; | ||
errTxt = `${err.code}: ${err.message}`; | ||
} | ||
catch (e) { | ||
errTxt = resp.statusText; | ||
} | ||
const errTxt = isErrorResponse(json) ? `${json.code}: ${json.message}` : resp.statusText; | ||
throw new Error(errTxt); | ||
@@ -66,0 +71,0 @@ } |
{ | ||
"name": "@gnosis.pm/safe-react-gateway-sdk", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
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
79747
1867