mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 07:26:11 +00:00
Merge pull request #2823 from Infisical/daniel/consolidate-request-ids
fix: consolidate reqId and requestId fields
This commit is contained in:
+1
-1
@@ -2,6 +2,6 @@ import "@fastify/request-context";
|
|||||||
|
|
||||||
declare module "@fastify/request-context" {
|
declare module "@fastify/request-context" {
|
||||||
interface RequestContextData {
|
interface RequestContextData {
|
||||||
requestId: string;
|
reqId: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ const redactedKeys = [
|
|||||||
|
|
||||||
const UNKNOWN_REQUEST_ID = "UNKNOWN_REQUEST_ID";
|
const UNKNOWN_REQUEST_ID = "UNKNOWN_REQUEST_ID";
|
||||||
|
|
||||||
const extractRequestId = () => {
|
const extractReqId = () => {
|
||||||
try {
|
try {
|
||||||
return requestContext.get("requestId") || UNKNOWN_REQUEST_ID;
|
return requestContext.get("reqId") || UNKNOWN_REQUEST_ID;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("failed to get request context", err);
|
console.log("failed to get request context", err);
|
||||||
return UNKNOWN_REQUEST_ID;
|
return UNKNOWN_REQUEST_ID;
|
||||||
@@ -133,22 +133,22 @@ export const initLogger = async () => {
|
|||||||
const wrapLogger = (originalLogger: Logger): CustomLogger => {
|
const wrapLogger = (originalLogger: Logger): CustomLogger => {
|
||||||
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
||||||
originalLogger.info = (obj: unknown, msg?: string, ...args: any[]) => {
|
originalLogger.info = (obj: unknown, msg?: string, ...args: any[]) => {
|
||||||
return originalLogger.child({ requestId: extractRequestId() }).info(obj, msg, ...args);
|
return originalLogger.child({ reqId: extractReqId() }).info(obj, msg, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
||||||
originalLogger.error = (obj: unknown, msg?: string, ...args: any[]) => {
|
originalLogger.error = (obj: unknown, msg?: string, ...args: any[]) => {
|
||||||
return originalLogger.child({ requestId: extractRequestId() }).error(obj, msg, ...args);
|
return originalLogger.child({ reqId: extractReqId() }).error(obj, msg, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
||||||
originalLogger.warn = (obj: unknown, msg?: string, ...args: any[]) => {
|
originalLogger.warn = (obj: unknown, msg?: string, ...args: any[]) => {
|
||||||
return originalLogger.child({ requestId: extractRequestId() }).warn(obj, msg, ...args);
|
return originalLogger.child({ reqId: extractReqId() }).warn(obj, msg, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
||||||
originalLogger.debug = (obj: unknown, msg?: string, ...args: any[]) => {
|
originalLogger.debug = (obj: unknown, msg?: string, ...args: any[]) => {
|
||||||
return originalLogger.child({ requestId: extractRequestId() }).debug(obj, msg, ...args);
|
return originalLogger.child({ reqId: extractReqId() }).debug(obj, msg, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
return originalLogger;
|
return originalLogger;
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ export const main = async ({ db, hsmModule, auditLogDb, smtp, logger, queue, key
|
|||||||
await server.register(maintenanceMode);
|
await server.register(maintenanceMode);
|
||||||
|
|
||||||
await server.register(fastifyRequestContext, {
|
await server.register(fastifyRequestContext, {
|
||||||
defaultStoreValues: (request) => ({
|
defaultStoreValues: (req) => ({
|
||||||
requestId: request.id,
|
reqId: req.id,
|
||||||
log: request.log.child({ requestId: request.id })
|
log: req.log.child({ reqId: req.id })
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -40,42 +40,42 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
|
|||||||
if (error instanceof BadRequestError) {
|
if (error instanceof BadRequestError) {
|
||||||
void res
|
void res
|
||||||
.status(HttpStatusCodes.BadRequest)
|
.status(HttpStatusCodes.BadRequest)
|
||||||
.send({ requestId: req.id, statusCode: HttpStatusCodes.BadRequest, message: error.message, error: error.name });
|
.send({ reqId: req.id, statusCode: HttpStatusCodes.BadRequest, message: error.message, error: error.name });
|
||||||
} else if (error instanceof NotFoundError) {
|
} else if (error instanceof NotFoundError) {
|
||||||
void res
|
void res
|
||||||
.status(HttpStatusCodes.NotFound)
|
.status(HttpStatusCodes.NotFound)
|
||||||
.send({ requestId: req.id, statusCode: HttpStatusCodes.NotFound, message: error.message, error: error.name });
|
.send({ reqId: req.id, statusCode: HttpStatusCodes.NotFound, message: error.message, error: error.name });
|
||||||
} else if (error instanceof UnauthorizedError) {
|
} else if (error instanceof UnauthorizedError) {
|
||||||
void res.status(HttpStatusCodes.Unauthorized).send({
|
void res.status(HttpStatusCodes.Unauthorized).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.Unauthorized,
|
statusCode: HttpStatusCodes.Unauthorized,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
error: error.name
|
error: error.name
|
||||||
});
|
});
|
||||||
} else if (error instanceof DatabaseError || error instanceof InternalServerError) {
|
} else if (error instanceof DatabaseError || error instanceof InternalServerError) {
|
||||||
void res.status(HttpStatusCodes.InternalServerError).send({
|
void res.status(HttpStatusCodes.InternalServerError).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.InternalServerError,
|
statusCode: HttpStatusCodes.InternalServerError,
|
||||||
message: "Something went wrong",
|
message: "Something went wrong",
|
||||||
error: error.name
|
error: error.name
|
||||||
});
|
});
|
||||||
} else if (error instanceof GatewayTimeoutError) {
|
} else if (error instanceof GatewayTimeoutError) {
|
||||||
void res.status(HttpStatusCodes.GatewayTimeout).send({
|
void res.status(HttpStatusCodes.GatewayTimeout).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.GatewayTimeout,
|
statusCode: HttpStatusCodes.GatewayTimeout,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
error: error.name
|
error: error.name
|
||||||
});
|
});
|
||||||
} else if (error instanceof ZodError) {
|
} else if (error instanceof ZodError) {
|
||||||
void res.status(HttpStatusCodes.UnprocessableContent).send({
|
void res.status(HttpStatusCodes.UnprocessableContent).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.UnprocessableContent,
|
statusCode: HttpStatusCodes.UnprocessableContent,
|
||||||
error: "ValidationFailure",
|
error: "ValidationFailure",
|
||||||
message: error.issues
|
message: error.issues
|
||||||
});
|
});
|
||||||
} else if (error instanceof ForbiddenError) {
|
} else if (error instanceof ForbiddenError) {
|
||||||
void res.status(HttpStatusCodes.Forbidden).send({
|
void res.status(HttpStatusCodes.Forbidden).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.Forbidden,
|
statusCode: HttpStatusCodes.Forbidden,
|
||||||
error: "PermissionDenied",
|
error: "PermissionDenied",
|
||||||
message: `You are not allowed to ${error.action} on ${error.subjectType}`,
|
message: `You are not allowed to ${error.action} on ${error.subjectType}`,
|
||||||
@@ -88,28 +88,28 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
|
|||||||
});
|
});
|
||||||
} else if (error instanceof ForbiddenRequestError) {
|
} else if (error instanceof ForbiddenRequestError) {
|
||||||
void res.status(HttpStatusCodes.Forbidden).send({
|
void res.status(HttpStatusCodes.Forbidden).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.Forbidden,
|
statusCode: HttpStatusCodes.Forbidden,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
error: error.name
|
error: error.name
|
||||||
});
|
});
|
||||||
} else if (error instanceof RateLimitError) {
|
} else if (error instanceof RateLimitError) {
|
||||||
void res.status(HttpStatusCodes.TooManyRequests).send({
|
void res.status(HttpStatusCodes.TooManyRequests).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.TooManyRequests,
|
statusCode: HttpStatusCodes.TooManyRequests,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
error: error.name
|
error: error.name
|
||||||
});
|
});
|
||||||
} else if (error instanceof ScimRequestError) {
|
} else if (error instanceof ScimRequestError) {
|
||||||
void res.status(error.status).send({
|
void res.status(error.status).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
schemas: error.schemas,
|
schemas: error.schemas,
|
||||||
status: error.status,
|
status: error.status,
|
||||||
detail: error.detail
|
detail: error.detail
|
||||||
});
|
});
|
||||||
} else if (error instanceof OidcAuthError) {
|
} else if (error instanceof OidcAuthError) {
|
||||||
void res.status(HttpStatusCodes.InternalServerError).send({
|
void res.status(HttpStatusCodes.InternalServerError).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.InternalServerError,
|
statusCode: HttpStatusCodes.InternalServerError,
|
||||||
message: error.message,
|
message: error.message,
|
||||||
error: error.name
|
error: error.name
|
||||||
@@ -128,14 +128,14 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
void res.status(HttpStatusCodes.Forbidden).send({
|
void res.status(HttpStatusCodes.Forbidden).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.Forbidden,
|
statusCode: HttpStatusCodes.Forbidden,
|
||||||
error: "TokenError",
|
error: "TokenError",
|
||||||
message: errorMessage
|
message: errorMessage
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
void res.status(HttpStatusCodes.InternalServerError).send({
|
void res.status(HttpStatusCodes.InternalServerError).send({
|
||||||
requestId: req.id,
|
reqId: req.id,
|
||||||
statusCode: HttpStatusCodes.InternalServerError,
|
statusCode: HttpStatusCodes.InternalServerError,
|
||||||
error: "InternalServerError",
|
error: "InternalServerError",
|
||||||
message: "Something went wrong"
|
message: "Something went wrong"
|
||||||
|
|||||||
@@ -30,25 +30,25 @@ export const integrationAuthPubSchema = IntegrationAuthsSchema.pick({
|
|||||||
|
|
||||||
export const DefaultResponseErrorsSchema = {
|
export const DefaultResponseErrorsSchema = {
|
||||||
400: z.object({
|
400: z.object({
|
||||||
requestId: z.string(),
|
reqId: z.string(),
|
||||||
statusCode: z.literal(400),
|
statusCode: z.literal(400),
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
error: z.string()
|
error: z.string()
|
||||||
}),
|
}),
|
||||||
404: z.object({
|
404: z.object({
|
||||||
requestId: z.string(),
|
reqId: z.string(),
|
||||||
statusCode: z.literal(404),
|
statusCode: z.literal(404),
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
error: z.string()
|
error: z.string()
|
||||||
}),
|
}),
|
||||||
401: z.object({
|
401: z.object({
|
||||||
requestId: z.string(),
|
reqId: z.string(),
|
||||||
statusCode: z.literal(401),
|
statusCode: z.literal(401),
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
error: z.string()
|
error: z.string()
|
||||||
}),
|
}),
|
||||||
403: z.object({
|
403: z.object({
|
||||||
requestId: z.string(),
|
reqId: z.string(),
|
||||||
statusCode: z.literal(403),
|
statusCode: z.literal(403),
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
details: z.any().optional(),
|
details: z.any().optional(),
|
||||||
@@ -56,13 +56,13 @@ export const DefaultResponseErrorsSchema = {
|
|||||||
}),
|
}),
|
||||||
// Zod errors return a message of varying shapes and sizes, so z.any() is used here
|
// Zod errors return a message of varying shapes and sizes, so z.any() is used here
|
||||||
422: z.object({
|
422: z.object({
|
||||||
requestId: z.string(),
|
reqId: z.string(),
|
||||||
statusCode: z.literal(422),
|
statusCode: z.literal(422),
|
||||||
message: z.any(),
|
message: z.any(),
|
||||||
error: z.string()
|
error: z.string()
|
||||||
}),
|
}),
|
||||||
500: z.object({
|
500: z.object({
|
||||||
requestId: z.string(),
|
reqId: z.string(),
|
||||||
statusCode: z.literal(500),
|
statusCode: z.literal(500),
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
error: z.string()
|
error: z.string()
|
||||||
|
|||||||
@@ -51,26 +51,26 @@ export enum ApiErrorTypes {
|
|||||||
|
|
||||||
export type TApiErrors =
|
export type TApiErrors =
|
||||||
| {
|
| {
|
||||||
requestId: string;
|
reqId: string;
|
||||||
error: ApiErrorTypes.ValidationError;
|
error: ApiErrorTypes.ValidationError;
|
||||||
message: ZodIssue[];
|
message: ZodIssue[];
|
||||||
statusCode: 422;
|
statusCode: 422;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
requestId: string;
|
reqId: string;
|
||||||
error: ApiErrorTypes.UnauthorizedError;
|
error: ApiErrorTypes.UnauthorizedError;
|
||||||
message: string;
|
message: string;
|
||||||
statusCode: 401;
|
statusCode: 401;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
requestId: string;
|
reqId: string;
|
||||||
error: ApiErrorTypes.ForbiddenError;
|
error: ApiErrorTypes.ForbiddenError;
|
||||||
message: string;
|
message: string;
|
||||||
details: PureAbility["rules"];
|
details: PureAbility["rules"];
|
||||||
statusCode: 403;
|
statusCode: 403;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
requestId: string;
|
reqId: string;
|
||||||
statusCode: 400;
|
statusCode: 400;
|
||||||
message: string;
|
message: string;
|
||||||
error: ApiErrorTypes.BadRequestError;
|
error: ApiErrorTypes.BadRequestError;
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ export const queryClient = new QueryClient({
|
|||||||
),
|
),
|
||||||
copyActions: [
|
copyActions: [
|
||||||
{
|
{
|
||||||
value: serverResponse.requestId,
|
value: serverResponse.reqId,
|
||||||
name: "Request ID",
|
name: "Request ID",
|
||||||
label: `Request ID: ${serverResponse.requestId}`
|
label: `Request ID: ${serverResponse.reqId}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -169,9 +169,9 @@ export const queryClient = new QueryClient({
|
|||||||
) : undefined,
|
) : undefined,
|
||||||
copyActions: [
|
copyActions: [
|
||||||
{
|
{
|
||||||
value: serverResponse.requestId,
|
value: serverResponse.reqId,
|
||||||
name: "Request ID",
|
name: "Request ID",
|
||||||
label: `Request ID: ${serverResponse.requestId}`
|
label: `Request ID: ${serverResponse.reqId}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -185,9 +185,9 @@ export const queryClient = new QueryClient({
|
|||||||
text: `${serverResponse.message}.`,
|
text: `${serverResponse.message}.`,
|
||||||
copyActions: [
|
copyActions: [
|
||||||
{
|
{
|
||||||
value: serverResponse.requestId,
|
value: serverResponse.reqId,
|
||||||
name: "Request ID",
|
name: "Request ID",
|
||||||
label: `Request ID: ${serverResponse.requestId}`
|
label: `Request ID: ${serverResponse.reqId}`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user