feat: enhance error messages in middleware to include request URL for better debugging
This commit is contained in:
parent
3ecbc54515
commit
1c2202f604
1 changed files with 7 additions and 7 deletions
|
|
@ -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({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue