diff --git a/src/api/addressApiLegacy.js b/src/api/addressApiLegacy.js index 8aa485d..de074a1 100644 --- a/src/api/addressApiLegacy.js +++ b/src/api/addressApiLegacy.js @@ -17,8 +17,8 @@ const addressApi = { } return undefined; }) - .catch(_error => { - // something wrong with request + .catch(error => { + console.error(`Failure obtaining address ${address} balance`, error); }); }, @@ -49,8 +49,8 @@ const addressApi = { } return undefined; }) - .catch(_error => { - // something wrong with request + .catch(error => { + console.error('Failure searching for addresses', error); }); }, }; diff --git a/src/api/graphvizApi.js b/src/api/graphvizApi.js index 611723d..6364d50 100644 --- a/src/api/graphvizApi.js +++ b/src/api/graphvizApi.js @@ -16,7 +16,9 @@ const graphvizApi = { return res.data; }, res => { - throw new Error(res.data.message); + throw new Error( + res?.data?.message || res?.message || 'Unknown error at get node neighbors' + ); } ); }, diff --git a/src/api/metadataApi.js b/src/api/metadataApi.js index 42e271a..2345bda 100644 --- a/src/api/metadataApi.js +++ b/src/api/metadataApi.js @@ -17,8 +17,8 @@ const metadataApi = { } return undefined; }) - .catch(_error => { - // something wrong with request + .catch(error => { + console.error(`Error fetching dag metadata for ${id}`, error); }); }, }; diff --git a/src/api/nanoApi.js b/src/api/nanoApi.js index 775804a..da6c0df 100644 --- a/src/api/nanoApi.js +++ b/src/api/nanoApi.js @@ -20,14 +20,14 @@ const nanoApi = { */ getState(id, fields, balances, calls) { const data = { id, fields, balances, calls }; - return requestExplorerServiceV1.get(`node_api/nc_state`, { params: data }).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/nc_state`, { params: data }) + .then(res => res.data) + .catch(err => { + throw new Error( + err?.data?.message || err?.message || `Unknown error on get nc state for ${id}` + ); + }); }, /** @@ -51,14 +51,12 @@ const nanoApi = { if (before) { data.before = before; } - return requestExplorerServiceV1.get(`node_api/nc_history`, { params: data }).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/nc_history`, { params: data }) + .then(res => res.data) + .catch(err => { + throw new Error(err?.data?.message || err?.message || `Unknown error on get nc history`); + }); }, /** @@ -70,14 +68,16 @@ const nanoApi = { */ getBlueprintInformation(blueprintId) { const data = { blueprint_id: blueprintId }; - return requestExplorerServiceV1.get(`node_api/nc_blueprint_information`, { params: data }).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/nc_blueprint_information`, { params: data }) + .then(res => res.data) + .catch(err => { + throw new Error( + err?.data?.message || + err?.message || + `Unknown error on get blueprint data for ${blueprintId}` + ); + }); }, /** @@ -89,14 +89,16 @@ const nanoApi = { */ getBlueprintSourceCode(blueprintId) { const data = { blueprint_id: blueprintId }; - return requestExplorerServiceV1.get(`node_api/nc_blueprint_source_code`, { params: data }).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/nc_blueprint_source_code`, { params: data }) + .then(res => res.data) + .catch(err => { + throw new Error( + err?.data?.message || + err?.message || + `Unknown error on get blueprint source code for ${blueprintId}` + ); + }); }, }; diff --git a/src/api/networkApi.js b/src/api/networkApi.js index fb05fbe..285be89 100644 --- a/src/api/networkApi.js +++ b/src/api/networkApi.js @@ -12,13 +12,13 @@ const networkApi = { return requestExplorerServiceV1 .get(`node`) .then(res => { - if (!res.data) { + if (!res?.data) { throw new Error('unknown_error'); } return res.data; }) .catch(res => { - throw new Error(res.data.message); + throw new Error(res?.data?.message || res?.message || 'Unknown error on get all nodes'); }); }, getPeer(hash) { @@ -31,7 +31,7 @@ const networkApi = { return res.data; }) .catch(res => { - throw new Error(res.data.message); + throw new Error(res?.data?.message || res?.message || `Unknown error on get node ${hash}`); }); }, }; diff --git a/src/api/tokenApi.js b/src/api/tokenApi.js index efd2e93..1f91763 100644 --- a/src/api/tokenApi.js +++ b/src/api/tokenApi.js @@ -10,38 +10,36 @@ import { TX_COUNT } from '../constants'; const tokenApi = { getList() { - return requestExplorerServiceV1.get(`node_api/tokens`).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/tokens`) + .then(res => res.data) + .catch(err => { + throw new Error(err?.data?.message || err?.message || `Unknown error on get tokens list`); + }); }, get(id) { const data = { id }; - return requestExplorerServiceV1.get(`node_api/token`, { params: data }).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/token`, { params: data }) + .then(res => res.data) + .catch(err => { + throw new Error( + err?.data?.message || err?.message || `Unknown error on get token data for ${id}` + ); + }); }, getHistory(id, timestamp, hash, page) { const data = { id, timestamp, hash, page, count: TX_COUNT }; - return requestExplorerServiceV1.get(`node_api/token_history`, { params: data }).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/token_history`, { params: data }) + .then(res => res.data) + .catch(err => { + throw new Error( + err?.data?.message || err?.message || `Unknown error on get history for ${id}` + ); + }); }, }; diff --git a/src/api/txApi.js b/src/api/txApi.js index 523145a..31b3e2d 100644 --- a/src/api/txApi.js +++ b/src/api/txApi.js @@ -91,14 +91,9 @@ const txApi = { */ getConfirmationData(id) { const data = { id }; - return requestExplorerServiceV1.get(`node_api/transaction_acc_weight`, { params: data }).then( - res => { - return res.data; - }, - res => { - return Promise.reject(res); - } - ); + return requestExplorerServiceV1 + .get(`node_api/transaction_acc_weight`, { params: data }) + .then(res => res.data); }, }; diff --git a/src/api/version.js b/src/api/version.js index 58c75b5..003d21a 100644 --- a/src/api/version.js +++ b/src/api/version.js @@ -9,14 +9,12 @@ import requestExplorerServiceV1 from './axiosInstance'; const versionApi = { getVersion() { - return requestExplorerServiceV1.get(`node_api/version`).then( - res => { - return res.data; - }, - res => { - throw new Error(res.data.message); - } - ); + return requestExplorerServiceV1 + .get(`node_api/version`) + .then(res => res.data) + .catch(err => { + throw new Error(err?.data?.message || err?.message || `Unknown error on get node version`); + }); }, };