Skip to content

Commit

Permalink
feat: add error logging in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijna-Raghavendra committed Feb 14, 2024
1 parent ce93c5a commit 443de7b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/backend/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import {
Application,
Context,
isHttpError,
Router,
Status,
} from "https://deno.land/x/[email protected]/mod.ts";
import { Session } from "https://deno.land/x/[email protected]/mod.ts";
import { create, verify } from "https://deno.land/x/[email protected]/mod.ts";
import { exec } from "https://deno.land/x/[email protected]/mod.ts";
import * as Sentry from "npm:@sentry/node";

export { Application, Context, create, exec, Router, Sentry, Session, verify };
export {
Application,
Context,
create,
exec,
isHttpError,
Router,
Sentry,
Session,
Status,
verify,
};
16 changes: 16 additions & 0 deletions src/backend/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
Application,
Context,
isHttpError,
Router,
Sentry,
Session,
Status,
} from "./dependencies.ts";
import { githubAuth, githubId } from "./auth/github.ts";
import { addSubdomain, deleteSubdomain, getSubdomains } from "./main.ts";
Expand All @@ -25,6 +27,20 @@ Sentry.init({
tracesSampleRate: 1.0,
});

app.use(async (ctx: Context, next) => {
try {
await next();
} catch (err) {
if (isHttpError(err)) {
ctx.response.status = err.status;
} else {
ctx.response.status = Status.InternalServerError;
}
Sentry.captureException(err);
ctx.response.body = { error: err.message };
}
});

app.use(Session.initMiddleware());

router
Expand Down

0 comments on commit 443de7b

Please sign in to comment.