diff --git a/client/src/pages/actions/actionsOpenalexFeedback.jsx b/client/src/pages/actions/actionsOpenalexFeedback.jsx index 2b0b21fb..9f324976 100644 --- a/client/src/pages/actions/actionsOpenalexFeedback.jsx +++ b/client/src/pages/actions/actionsOpenalexFeedback.jsx @@ -14,20 +14,30 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) { const [validEmail, setValidEmail] = useState(null); const { toast } = useToast(); - const openModal = () => { + const switchModal = () => { setIsModalOpen((prev) => !prev); }; - const feedback = () => { - sendGitHubIssue({ data: allOpenalexCorrections, email: userEmail }); - toast({ - description: `${allOpenalexCorrections.length} correction(s) to OpenAlex have been saved - - see https://github.com/dataesr/openalex-affiliations/issues`, - id: 'saveOpenAlex', - title: 'OpenAlex corrections sent', - toastType: 'success', - }); - openModal(); + const feedback = async () => { + try { + await sendGitHubIssue({ data: allOpenalexCorrections, email: userEmail }); + toast({ + description: `${allOpenalexCorrections.length} correction(s) to OpenAlex have been saved - + see https://github.com/dataesr/openalex-affiliations/issues`, + id: 'saveOpenAlex', + title: 'OpenAlex corrections sent', + toastType: 'success', + }); + } catch (error) { + toast({ + description: error.message, + id: 'errorOpenAlex', + title: 'Error while sending OpenAlex corrections', + toastType: 'error', + }); + } finally { + switchModal(); + } }; useEffect(() => { @@ -41,12 +51,12 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) { <> - + Improve OpenAlex data diff --git a/client/src/utils/github.jsx b/client/src/utils/github.jsx index e0f32b9b..44643148 100644 --- a/client/src/utils/github.jsx +++ b/client/src/utils/github.jsx @@ -10,7 +10,7 @@ const sendGitHubIssue = async (data) => { headers: { 'Content-Type': 'application/json' }, }).then((response) => { if (response.ok) return response.json(); - return 'Oops... GitHub request error'; + throw new Error(response.statusText); }); }; diff --git a/client/src/utils/templates.jsx b/client/src/utils/templates.jsx index 838e9bca..927bcccf 100644 --- a/client/src/utils/templates.jsx +++ b/client/src/utils/templates.jsx @@ -142,13 +142,6 @@ const nameTemplate = (rowData) => {status[rowData?.status ?? rowData]?.label}; -const resetCorrection = (rowData, allAffiliations) => { - console.log('ttt', rowData); - const row = { rowData }; - row.rowData.hasCorrection = false; - row.rowData.rorsToCorrect = rowData.rors.map((e) => e.rorId).join(';'); -}; - const hasCorrectionTemplate = (rowData) => (rowData?.hasCorrection ? ( {correction.corrected.label} diff --git a/server/src/routes/github.routes.js b/server/src/routes/github.routes.js index 8d725c16..6b3b4006 100644 --- a/server/src/routes/github.routes.js +++ b/server/src/routes/github.routes.js @@ -32,7 +32,7 @@ const createIssue = (issue, email) => { ); }, onSecondaryRateLimit: (retryAfter, options) => { - // Retry 3 times after hitting a rate limit error, then give up + // Retry 5 times after hitting a rate limit error after 60 seconds if (options.request.retryCount <= 5) { return true; } @@ -59,7 +59,7 @@ const createIssue = (issue, email) => { } body += `works_examples: ${workIds}\n`; body += `contact: ${encrypt(email.split('@')[0])} @ ${email.split('@')[1]}\n`; - octokit.rest.issues.create({ + return octokit.rest.issues.create({ body, owner: 'dataesr', repo: 'openalex-affiliations', @@ -71,9 +71,10 @@ router.route('/github-issue') .post(async (req, res) => { const data = req.body?.data || []; const email = req.body?.email || ''; - const promises = data.map((item) => createIssue(item, email)); - await Promise.all(promises); - res.status(200).json({ message: 'GitHub Issues created' }); + const promises = data.map((item) => createIssue(item, email).catch((error) => error)); + const results = await Promise.all(promises); + const firstError = results.find((result) => !result.status.toString().startsWith('2')); + res.status(firstError?.status ?? 200).json({ message: firstError?.message ?? 'GitHub issues created' }); }); export default router;