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

Better error reporting #121

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 0 additions & 1 deletion ejs-views/pages/404.ejs

This file was deleted.

1 change: 0 additions & 1 deletion ejs-views/pages/505.ejs

This file was deleted.

21 changes: 21 additions & 0 deletions ejs-views/pages/error.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%- include('../partials/header', { page }); %>

<article>
<div class="w-full border border-secondary rounded p-3">
<span class="text-3xl text-primary">This Page encountered an Error!</span>
confused-Techie marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div id="readme" class="mt-12 prose max-w-none">
<h1>
If you think you're seeing this page in error. Please report an issue on
<a href="https://github.com/pulsar-edit/package-frontend">GitHub</a> or
confused-Techie marked this conversation as resolved.
Show resolved Hide resolved
<a href="https://discord.gg/7aEbB9dGRT">Discord</a>.
</h1>
<pre>
<code class="hljs language-json">
<%-error%>
</code>
</pre>
</div>
</article>

<%- include('../partials/footer'); %>
26 changes: 24 additions & 2 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ async function fullListingPage(req, res, timecop) {
og_image_type: "image/svg+xml"
}});
} catch(err) {
utils.displayError(req, res, err);
utils.displayError(req, res, {
error: utils.modifyErrorText(err),
dev: DEV,
timecop: false,
page: {
name: "PPR Error Page",
og_url: "https://web.pulsar-edit.dev/packages",
og_description: "The Pulsar Package Repository",
og_image: "https://web.pulsar-edit.dev/public/pulsar_name.svg",
og_image_type: "image/svg+xml"
}
});
}
}

Expand All @@ -54,7 +65,18 @@ async function singlePackageListing(req, res, timecop) {
og_image_height: 600,
}});
} catch(err) {
utils.displayError(req, res, err);
utils.displayError(req, res, {
error: utils.modifyErrorText(err),
dev: DEV,
timecop: false,
page: {
name: "PPR Error Page",
og_url: "https://web.pulsar-edit.dev/packages",
og_description: "The Pulsar Package Repository",
og_image: "https://web.pulsar-edit.dev/public/pulsar_name.svg",
og_image_type: "image/svg+xml"
}
});
}
}

Expand Down
33 changes: 22 additions & 11 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ const reg = require("./reg.js");

// Collection of utility functions for the frontend

async function displayError(req, res, errStatus) {
switch(errStatus) {
case 404:
res.status(404).render('404');
break;
case 505:
res.status(505).render('505');
break;
default:
res.status(505).render('505');
break;
async function displayError(req, res, details) {
console.error(details);
res.status(500).render('error', details);
}

function modifyErrorText(err) {
// This function takes an error object, or error message string, and attempts
// to find the optimal formatting of the message to display to users.

if (typeof err === "object") {
if (typeof err.status === "number") {
// This is likely an error thrown from `superagent`
let text = `'${err.status}' Received from '${err?.response?.req?.host}${err?.response?.req?.path}'\n\t\t ${err.toString()}`;
return text;
} else {
// TODO Additional possibilities added here
return err;
}
} else {
// We likely already have an error message string
return err;
}
}

Expand Down Expand Up @@ -463,4 +473,5 @@ module.exports = {
prepareForDetail,
getPagination,
Timecop,
modifyErrorText
};