diff --git a/backend/src/routes/livepeer.js b/backend/src/routes/livepeer.js index 53971cf..f787f34 100644 --- a/backend/src/routes/livepeer.js +++ b/backend/src/routes/livepeer.js @@ -468,6 +468,10 @@ const parseOrchestrator = async function (reqAddr) { `; orchestratorObj = await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", orchQuery); orchestratorObj = orchestratorObj.transcoders[0]; + // Not found + if (!orchestratorObj){ + return JSON.stringify({}); + } orchestratorObj.lastGet = now; if (wasCached) { for (var orch of orchestratorCache) { @@ -493,6 +497,7 @@ apiRouter.get("/getOrchestrator", async (req, res) => { const reqObj = await parseOrchestrator(reqOrch); res.send(reqObj); } catch (err) { + console.log(err); res.status(400).send(err); } }); @@ -501,6 +506,7 @@ apiRouter.get("/getOrchestrator/:orch", async (req, res) => { const reqObj = await parseOrchestrator(req.params.orch); res.send(reqObj); } catch (err) { + console.log(err); res.status(400).send(err); } }); @@ -509,6 +515,7 @@ apiRouter.post("/getOrchestrator", async (req, res) => { const reqObj = await parseOrchestrator(req.body.orchAddr); res.send(reqObj); } catch (err) { + console.log(err); res.status(400).send(err); } }); @@ -549,6 +556,10 @@ const parseDelegator = async function (reqAddr) { `; delegatorObj = await request("https://api.thegraph.com/subgraphs/name/livepeer/arbitrum-one", delegatorQuery); delegatorObj = delegatorObj.delegators[0]; + // Not found + if (!delegatorObj){ + return {}; + } delegatorObj.lastGet = now; if (wasCached) { for (var delegator of delegatorCache) { diff --git a/src/actions/livepeer.js b/src/actions/livepeer.js index 7ca5baa..7fb2a87 100644 --- a/src/actions/livepeer.js +++ b/src/actions/livepeer.js @@ -358,7 +358,15 @@ export const getOrchestratorInfo = (orchAddr) => async dispatch => { const response = await apiUtil.getOrchestratorInfo(orchAddr); const data = await response.json(); if (response.ok) { - return dispatch(setOrchestratorInfo(data)); + if (data && data.id){ + return dispatch(setOrchestratorInfo(data)); + }else{ + const response = await apiUtil.getOrchestratorByDelegator(orchAddr); + const data = await response.json(); + if (response.ok) { + return dispatch(setOrchestratorInfo(data)); + } + } } return dispatch(receiveErrors(data)); }; \ No newline at end of file diff --git a/src/util/livepeer.js b/src/util/livepeer.js index c93673c..f11f8be 100644 --- a/src/util/livepeer.js +++ b/src/util/livepeer.js @@ -43,4 +43,13 @@ export const getOrchestratorInfo = (orchAddr) => ( "Content-Type": "application/json" } }) +); + +export const getOrchestratorByDelegator = (delAddr) => ( + fetch("api/livepeer/getOrchestratorByDelegator/" + delAddr, { + method: "GET", + headers: { + "Content-Type": "application/json" + } + }) ); \ No newline at end of file