Refactor to accommodate authentication, transaction and pagination states together (#4636)

* fix: refactor to accommodate authentication, transaction and pagination together into ctx.state

* feat: allow passing response type to APIContext
This commit is contained in:
Apoorv Mishra
2023-01-04 23:51:44 +05:30
committed by GitHub
parent bb568d2e62
commit f4461573de
31 changed files with 753 additions and 675 deletions

View File

@@ -1,6 +1,6 @@
import * as Sentry from "@sentry/node";
import env from "@server/env";
import { ContextWithState } from "../types";
import { AppContext } from "@server/types";
if (env.SENTRY_DSN) {
Sentry.init({
@@ -29,7 +29,7 @@ if (env.SENTRY_DSN) {
});
}
export function requestErrorHandler(error: any, ctx: ContextWithState) {
export function requestErrorHandler(error: any, ctx: AppContext) {
// we don't need to report every time a request stops to the bug tracker
if (error.code === "EPIPE" || error.code === "ECONNRESET") {
console.warn("Connection error", {
@@ -46,17 +46,17 @@ export function requestErrorHandler(error: any, ctx: ContextWithState) {
scope.setTag("request_id", requestId as string);
}
const authType = ctx.state?.authType ?? undefined;
const authType = ctx.state?.auth?.type ?? undefined;
if (authType) {
scope.setTag("auth_type", authType);
}
const teamId = ctx.state?.user?.teamId ?? undefined;
const teamId = ctx.state?.auth?.user?.teamId ?? undefined;
if (teamId) {
scope.setTag("team_id", teamId);
}
const userId = ctx.state?.user?.id ?? undefined;
const userId = ctx.state?.auth?.user?.id ?? undefined;
if (userId) {
scope.setUser({
id: userId,