feat: enhance error messages in middleware to include request URL for better debugging

This commit is contained in:
Marco Pedone 2026-03-18 17:39:12 +01:00
parent 3ecbc54515
commit 1c2202f604

View file

@ -149,7 +149,7 @@ const enforceUserIsAuthed = t.middleware(({ ctx, next, path }) => {
if (!ctx.session) { if (!ctx.session) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `User is not logged, error in path: ${path}`, message: `User is not logged, error in path: ${path} [${ctx.req?.url}]`,
}); });
} }
@ -175,7 +175,7 @@ const enforceUserIsAuthedOrOverride = t.middleware(({ ctx, next, path }) => {
if (!ctx.session) { if (!ctx.session) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `User is not logged, error in path: ${path}`, message: `User is not logged, error in path: ${path} [${ctx.req?.url}]`,
}); });
} }
@ -205,7 +205,7 @@ const enforceUserIsAdmin = t.middleware(({ ctx, next, path }) => {
if (!ctx.session || !ctx.session.isAdmin) { if (!ctx.session || !ctx.session.isAdmin) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `User is not Admin, error in path: ${path}`, message: `User is not Admin, error in path: ${path} [${ctx.req?.url}]`,
}); });
} }
return next({ return next({
@ -243,14 +243,14 @@ const enforceProtectedApi = t.middleware(async ({ ctx, next, path }) => {
if (!ctx.req || !ctx.res) { if (!ctx.req || !ctx.res) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `No request or response object, error in path: ${path}`, message: `No request or response object, error in path: ${path} [${ctx.req?.url}]`,
}); });
} }
const basicAuth = ctx.req.headers.authorization; const basicAuth = ctx.req.headers.authorization;
if (!basicAuth) { if (!basicAuth) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `No Auth header found: ${path}`, message: `No Auth header found: ${path} [${ctx.req?.url}]`,
}); });
} }
@ -259,7 +259,7 @@ const enforceProtectedApi = t.middleware(async ({ ctx, next, path }) => {
if (!authValue) { if (!authValue) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `Auth value invalid: ${path}`, message: `Auth value invalid: ${path} [${ctx.req?.url}]`,
}); });
} }
@ -268,7 +268,7 @@ const enforceProtectedApi = t.middleware(async ({ ctx, next, path }) => {
if (user !== env.EXP_API_USER || pwd !== env.EXP_API_PASS) { if (user !== env.EXP_API_USER || pwd !== env.EXP_API_PASS) {
throw new TRPCError({ throw new TRPCError({
code: "UNAUTHORIZED", code: "UNAUTHORIZED",
message: `User or Secret not valid: ${path}`, message: `User or Secret not valid: ${path} [${ctx.req?.url}]`,
}); });
} }
return next({ return next({