mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-16 14:59:07 +02:00
Improve error handling
This commit is contained in:
@@ -118,10 +118,8 @@ export function isOwnerCoauthorOrAdmin(repo: Repository, user: User) {
|
|||||||
function printError(error: any, req?: express.Request) {
|
function printError(error: any, req?: express.Request) {
|
||||||
if (error instanceof AnonymousError) {
|
if (error instanceof AnonymousError) {
|
||||||
if (req?.originalUrl === "/api/repo/undefined/options") return;
|
if (req?.originalUrl === "/api/repo/undefined/options") return;
|
||||||
const payload = {
|
const payload: Record<string, unknown> = serializeError(error);
|
||||||
...serializeError(error),
|
if (req?.originalUrl) payload.url = req.originalUrl;
|
||||||
url: req?.originalUrl,
|
|
||||||
};
|
|
||||||
// Use the error's snake_case message as the logger summary so the admin
|
// Use the error's snake_case message as the logger summary so the admin
|
||||||
// Errors page surfaces something meaningful (e.g. "repoId_already_used")
|
// Errors page surfaces something meaningful (e.g. "repoId_already_used")
|
||||||
// instead of a generic "anonymous error" wrapper.
|
// instead of a generic "anonymous error" wrapper.
|
||||||
@@ -136,10 +134,9 @@ function printError(error: any, req?: express.Request) {
|
|||||||
logger.error(summary, payload);
|
logger.error(summary, payload);
|
||||||
}
|
}
|
||||||
} else if (error instanceof HTTPError) {
|
} else if (error instanceof HTTPError) {
|
||||||
logger.error(error.code || error.name || "HTTPError", {
|
const payload: Record<string, unknown> = serializeError(error);
|
||||||
...serializeError(error),
|
if (req?.originalUrl) payload.url = req.originalUrl;
|
||||||
url: req?.originalUrl,
|
logger.error(error.code || error.name || "HTTPError", payload);
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
// Unhandled errors: use the error class name (SyntaxError, TypeError,
|
// Unhandled errors: use the error class name (SyntaxError, TypeError,
|
||||||
// RangeError, ...) as the summary so the admin page shows
|
// RangeError, ...) as the summary so the admin page shows
|
||||||
|
|||||||
Reference in New Issue
Block a user