From 90285249ecc32b209f68ea7cb785d8f5467cff89 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Mon, 22 Feb 2021 13:21:27 +0000 Subject: [PATCH] log page props errors to Sentry Wrap workflow API calls in try/catch and log Node errors to Sentry. --- .../fetchWorkflowsHelper.js | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.js b/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.js index 0b6488ffd34..9fc0960a66d 100644 --- a/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.js +++ b/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.js @@ -1,15 +1,23 @@ import { panoptes } from '@zooniverse/panoptes-js' import fetch from 'node-fetch' +import { logNodeError } from '@helpers/logger' + async function fetchWorkflowData (activeWorkflows, env) { - const query = { - complete: false, - env, - fields: 'completeness,display_name,grouped', - id: activeWorkflows.join(',') + let workflows = [] + try { + const query = { + complete: false, + env, + fields: 'completeness,display_name,grouped', + id: activeWorkflows.join(',') + } + const response = await panoptes.get('/workflows', query) + workflows = response.body.workflows + } catch (error) { + console.error(error) + logNodeError(error) } - const response = await panoptes.get('/workflows', query) - const { workflows } = response.body return workflows } @@ -25,21 +33,28 @@ async function fetchSubjectSetData(subjectSetIDs, env) { await Promise.allSettled(subject_sets.map(subjectSet => fetchPreviewImage(subjectSet, env))) } catch (error) { console.error(error) + logNodeError(error) } return subject_sets } -function fetchDisplayNames (language, activeWorkflows, env) { - return panoptes - .get('/translations', { +async function fetchDisplayNames (language, activeWorkflows, env) { + let displayNames = {} + try { + const response = await panoptes.get('/translations', { env, fields: 'strings,translated_id', language, 'translated_id': activeWorkflows.join(','), 'translated_type': 'workflow' }) - .then(response => response.body.translations) - .then(createDisplayNamesMap) + const { translations } = response.body + displayNames = createDisplayNamesMap(translations) + } catch (error) { + console.error(error) + logNodeError(error) + } + return displayNames } async function fetchWorkflowCellectStatus(workflow) { @@ -52,6 +67,7 @@ async function fetchWorkflowCellectStatus(workflow) { groups = body.groups ?? {} } catch (error) { console.error(error) + logNodeError(error) } } return groups