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 1 commit
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
14 changes: 12 additions & 2 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 @@ -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.)'
)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of a custom error message for the "theme-missing" error is a good enhancement for user feedback. However, the HTTP status code 200 is not appropriate for an error condition. Consider using a 4xx status code to indicate client-side errors.

- .status(200)
+ .status(404) // or another appropriate 4xx error code

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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.)'
)
);
if (e.message === 'theme-missing') {
return res
.status(404) // or another appropriate 4xx error code
.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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTTP status code for the generic error message should also reflect an error condition. Consider using a 4xx or 5xx status code to indicate client or server errors, respectively.

- .status(200)
+ .status(500) // or another appropriate error code

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return res
.status(200)
.send(
return res
.status(500) // or another appropriate error code
.send(

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