diff --git a/api/network-explorer.js b/api/network-explorer.js index c5057a69..d713e63d 100644 --- a/api/network-explorer.js +++ b/api/network-explorer.js @@ -7,6 +7,7 @@ import {loadBlockIndex} from './loaders/blocks/index'; import {loadBlockDetail} from './loaders/blocks/detail'; import {loadTransactionIndex} from './loaders/transactions/index'; import {loadTransactionDetail} from './loaders/transactions/detail'; +import {FriendlyGet} from './friendlyGet'; function prettify(req, data) { const isPretty = req.query && req.query.pretty === 'true'; @@ -35,9 +36,16 @@ export function addNetworkExplorerRoutes(redisX, app) { const start = q.start || '+'; const count = q.count ? parseInt(q.count) : DEFAULT_PAGE_SIZE; const direction = q.direction || '-'; - const rawData = await loadBlockIndex(redisX, start, count, direction); + const {__errors__, rawData} = await new FriendlyGet() + .with('rawData', loadBlockIndex(redisX, start, count, direction), {}) + .get(); - res.send(prettify(req, new BlockIndexView().asVersion(rawData, version))); + res.send( + prettify( + req, + new BlockIndexView().asVersion(rawData, __errors__, version), + ), + ); }); // Network Explorer Block Detail @@ -45,9 +53,16 @@ export function addNetworkExplorerRoutes(redisX, app) { const q = req.query || {}; const version = q.v || 'BlockDetailView@latest'; - const rawData = await loadBlockDetail(redisX, req.params.id, version); + const {__errors__, rawData} = await new FriendlyGet() + .with('rawData', loadBlockDetail(redisX, req.params.id, version), {}) + .get(); - res.send(prettify(req, new BlockDetailView().asVersion(rawData, version))); + res.send( + prettify( + req, + new BlockDetailView().asVersion(rawData, __errors__, version), + ), + ); }); // Network Explorer Transaction Index @@ -58,10 +73,19 @@ export function addNetworkExplorerRoutes(redisX, app) { const start = q.start || '+'; const count = q.count ? parseInt(q.count) : DEFAULT_PAGE_SIZE; const direction = q.direction || '-'; - const rawData = await loadTransactionIndex(redisX, start, count, direction); + const {__errors__, rawData} = await new FriendlyGet() + .with( + 'rawData', + loadTransactionIndex(redisX, start, count, direction), + {}, + ) + .get(); res.send( - prettify(req, new TransactionIndexView().asVersion(rawData, version)), + prettify( + req, + new TransactionIndexView().asVersion(rawData, __errors__, version), + ), ); }); @@ -70,10 +94,19 @@ export function addNetworkExplorerRoutes(redisX, app) { const q = req.query || {}; const version = q.v || 'TransactionDetailView@latest'; - const rawData = await loadTransactionDetail(redisX, req.params.id, version); + const {__errors__, rawData} = await new FriendlyGet() + .with( + 'rawData', + loadTransactionDetail(redisX, req.params.id, version), + {}, + ) + .get(); res.send( - prettify(req, new TransactionDetailView().asVersion(rawData, version)), + prettify( + req, + new TransactionDetailView().asVersion(rawData, __errors__, version), + ), ); }); } diff --git a/api/views/blocks/detail.js b/api/views/blocks/detail.js index 5de67cb4..5ddfab65 100644 --- a/api/views/blocks/detail.js +++ b/api/views/blocks/detail.js @@ -7,7 +7,14 @@ const __VERSION__ = 'BlockDetailView@1.0.0'; export class BlockDetailView { - asVersion(rawData, version) { + asVersion(rawData, __errors__, version) { + if (__errors__) { + return { + __VERSION__, + __errors__, + }; + } + const entries = rawData.entries; const blockData = rawData.block; diff --git a/api/views/blocks/index.js b/api/views/blocks/index.js index 1fba9013..401fd9d9 100644 --- a/api/views/blocks/index.js +++ b/api/views/blocks/index.js @@ -8,7 +8,14 @@ import _ from 'lodash'; */ const __VERSION__ = 'BlockIndexView@1.0.0'; export class BlockIndexView { - asVersion(rawData, version) { + asVersion(rawData, __errors__, version) { + if (__errors__) { + return { + __VERSION__, + __errors__, + }; + } + const timelineData = rawData.timelinePage; const timelineInfo = rawData.timelineInfo; diff --git a/api/views/transactions/detail.js b/api/views/transactions/detail.js index 607dc33f..309a51be 100644 --- a/api/views/transactions/detail.js +++ b/api/views/transactions/detail.js @@ -8,7 +8,14 @@ import _ from 'lodash'; */ const __VERSION__ = 'TransactionDetailView@1.0.0'; export class TransactionDetailView { - asVersion(rawData, version) { + asVersion(rawData, __errors__, version) { + if (__errors__) { + return { + __VERSION__, + __errors__, + }; + } + const transactionData = rawData.transaction; const entryData = rawData.entry; const blockData = rawData.block; diff --git a/api/views/transactions/index.js b/api/views/transactions/index.js index 284b174b..dcc2cae9 100644 --- a/api/views/transactions/index.js +++ b/api/views/transactions/index.js @@ -8,7 +8,14 @@ import _ from 'lodash'; */ const __VERSION__ = 'TransactionIndexView@1.0.0'; export class TransactionIndexView { - asVersion(rawData, version) { + asVersion(rawData, __errors__, version) { + if (__errors__) { + return { + __VERSION__, + __errors__, + }; + } + const timelineData = rawData.timelinePage; const timelineInfo = rawData.timelineInfo;