Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a link to a github issue when themes are missing #37

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions apps/registry/pages/api/[payload].js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 =
Expand All @@ -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') +
`

Expand Down Expand Up @@ -172,9 +172,19 @@ ${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(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.)'
)
);
}

return res
.status(200)
.status(400)
.send(
failMessage(
'Cannot format resume, no idea why #likely-a-validation-error'
Expand Down
5 changes: 5 additions & 0 deletions apps/registry/pages/api/formatters/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading