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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user