Skip to content

Commit

Permalink
log page props errors to Sentry
Browse files Browse the repository at this point in the history
Wrap workflow API calls in try/catch and log Node errors to Sentry.
  • Loading branch information
eatyourgreens committed Feb 22, 2021
1 parent f92626b commit 9028524
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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) {
Expand All @@ -52,6 +67,7 @@ async function fetchWorkflowCellectStatus(workflow) {
groups = body.groups ?? {}
} catch (error) {
console.error(error)
logNodeError(error)
}
}
return groups
Expand Down

0 comments on commit 9028524

Please sign in to comment.