From 6c2b30e7fad64038f0ba03699f01277b8b5fbf52 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 29 Nov 2023 20:31:41 +1100 Subject: [PATCH 1/2] feat: add a link to a github issue when themes are missing --- apps/registry/pages/api/[payload].js | 14 ++++++++++++-- apps/registry/pages/api/formatters/template.js | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/registry/pages/api/[payload].js b/apps/registry/pages/api/[payload].js index d014a58..3e5897c 100644 --- a/apps/registry/pages/api/[payload].js +++ b/apps/registry/pages/api/[payload].js @@ -54,7 +54,7 @@ export default async function handler(req, res) { const formatter = FORMATTERS[fileType]; if (!formatter) { - return res.status(200).send(failMessage('not supported formatted')); + return res.status(200).send(failMessage('not supported formatter')); } if ( @@ -172,7 +172,17 @@ ${JSON.stringify(validation.errors, null, 2)} try { formatted = await formatter.format(selectedResume, options); } catch (e) { - console.log(e); + // @todo - do this better + if (e.message === 'theme-missing') { + return res + .status(200) + .send( + failMessage( + 'This theme is currently unsupported. Please visit this Github issue to request it https://github.com/jsonresume/jsonresume.org/issues/36 (unfortunately we have recently (11/2023) disabled a bunch of legacy themes due to critical flaws in them, please request if you would like them back.)' + ) + ); + } + return res .status(200) .send( diff --git a/apps/registry/pages/api/formatters/template.js b/apps/registry/pages/api/formatters/template.js index 074b202..0afcab6 100644 --- a/apps/registry/pages/api/formatters/template.js +++ b/apps/registry/pages/api/formatters/template.js @@ -48,6 +48,11 @@ const getTheme = (theme) => { const format = async function (resume, options) { const theme = options.theme ?? 'elegant'; const themeRenderer = getTheme(theme); + + if (!themeRenderer) { + throw new Error('theme-missing'); + } + const resumeHTML = themeRenderer.render(resume); return { From d5f4df56be4a056446ed6977131d6302f0ff97fb Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 29 Nov 2023 20:44:06 +1100 Subject: [PATCH 2/2] tweak: return 400's --- apps/registry/pages/api/[payload].js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/registry/pages/api/[payload].js b/apps/registry/pages/api/[payload].js index 3e5897c..1f45136 100644 --- a/apps/registry/pages/api/[payload].js +++ b/apps/registry/pages/api/[payload].js @@ -120,7 +120,7 @@ export default async function handler(req, res) { }); } catch (e) { // If gist url is invalid, flush the gistid in cache - return res.status(200).send(failMessage('Cannot fetch gist, no idea why')); + return res.status(400).send(failMessage('Cannot fetch gist, no idea why')); } let realTheme = @@ -132,7 +132,7 @@ export default async function handler(req, res) { const validation = v.validate(selectedResume, schema); if (!validation.valid) { - return res.status(200).send( + return res.status(400).send( failMessage('Validation failed') + ` @@ -175,7 +175,7 @@ ${JSON.stringify(validation.errors, null, 2)} // @todo - do this better if (e.message === 'theme-missing') { return res - .status(200) + .status(400) .send( failMessage( 'This theme is currently unsupported. Please visit this Github issue to request it https://github.com/jsonresume/jsonresume.org/issues/36 (unfortunately we have recently (11/2023) disabled a bunch of legacy themes due to critical flaws in them, please request if you would like them back.)' @@ -184,7 +184,7 @@ ${JSON.stringify(validation.errors, null, 2)} } return res - .status(200) + .status(400) .send( failMessage( 'Cannot format resume, no idea why #likely-a-validation-error'