logs
This commit is contained in:
@@ -224,8 +224,28 @@ export class OidcInteractionController {
|
||||
const cookieHeader = request.headers.cookie ?? '';
|
||||
const hasCookieHeader = Boolean(cookieHeader);
|
||||
const hasInteractionCookie = /(?:^|;\s*)_interaction=/.test(cookieHeader);
|
||||
const errorName = error instanceof Error ? error.name : typeof error;
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
const errorStack = error instanceof Error ? error.stack : undefined;
|
||||
const logPayload = {
|
||||
uid,
|
||||
errorName,
|
||||
errorMessage,
|
||||
hasCookieHeader,
|
||||
hasInteractionCookie,
|
||||
method: request.method,
|
||||
path: request.originalUrl || request.url,
|
||||
host: request.headers.host,
|
||||
forwardedProto: request.headers['x-forwarded-proto'],
|
||||
forwardedHost: request.headers['x-forwarded-host'],
|
||||
referer: request.headers.referer,
|
||||
userAgent: request.headers['user-agent'],
|
||||
correlationId: this.requestContext.get().correlationId,
|
||||
};
|
||||
|
||||
console.error('[OIDC_INTERACTION_SESSION_NOT_FOUND]', JSON.stringify(logPayload), errorStack ?? '');
|
||||
this.logger.warn(
|
||||
`OIDC interaction session not found uid=${uid} hasCookieHeader=${hasCookieHeader} hasInteractionCookie=${hasInteractionCookie} host=${request.headers.host ?? ''} forwardedProto=${request.headers['x-forwarded-proto'] ?? ''}`,
|
||||
`OIDC interaction session not found uid=${uid} error=${errorName}:${errorMessage} hasCookieHeader=${hasCookieHeader} hasInteractionCookie=${hasInteractionCookie} host=${request.headers.host ?? ''} forwardedProto=${request.headers['x-forwarded-proto'] ?? ''}`,
|
||||
);
|
||||
|
||||
await this.applicationErrorLogger.log({
|
||||
|
||||
@@ -326,6 +326,7 @@ export class OidcProviderService implements OnModuleInit {
|
||||
|
||||
for (const eventName of errorEvents) {
|
||||
eventSource.on(eventName, (ctx, error) => {
|
||||
this.consoleLogOidcProviderError(eventName, ctx, error);
|
||||
this.logOidcProviderError(eventName, ctx, error).catch((logError) => {
|
||||
const message = logError instanceof Error ? logError.message : String(logError);
|
||||
this.logger.error(`OIDC provider error logging failed for ${eventName}: ${message}`);
|
||||
@@ -388,6 +389,46 @@ export class OidcProviderService implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
private consoleLogOidcProviderError(eventName: string, ctx: unknown, error: unknown): void {
|
||||
const oidcContext = ctx as {
|
||||
method?: string;
|
||||
path?: string;
|
||||
status?: number;
|
||||
query?: Record<string, unknown>;
|
||||
req?: { headers?: Record<string, string | string[] | undefined> };
|
||||
oidc?: {
|
||||
route?: string;
|
||||
client?: { clientId?: string };
|
||||
params?: Record<string, unknown>;
|
||||
};
|
||||
};
|
||||
const params = oidcContext.oidc?.params ?? oidcContext.query ?? {};
|
||||
const errorName = error instanceof Error ? error.name : typeof error;
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
const errorStack = error instanceof Error ? error.stack : undefined;
|
||||
|
||||
console.error(
|
||||
'[OIDC_PROVIDER_ERROR]',
|
||||
JSON.stringify({
|
||||
eventName,
|
||||
errorName,
|
||||
errorMessage,
|
||||
method: oidcContext.method,
|
||||
path: oidcContext.path,
|
||||
status: oidcContext.status,
|
||||
route: oidcContext.oidc?.route,
|
||||
clientId: oidcContext.oidc?.client?.clientId ?? params.client_id,
|
||||
redirectUri: params.redirect_uri,
|
||||
responseType: params.response_type,
|
||||
scope: params.scope,
|
||||
host: oidcContext.req?.headers?.host,
|
||||
forwardedProto: oidcContext.req?.headers?.['x-forwarded-proto'],
|
||||
forwardedHost: oidcContext.req?.headers?.['x-forwarded-host'],
|
||||
}),
|
||||
errorStack ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
private errorProperty(error: unknown, property: string): unknown {
|
||||
if (!error || typeof error !== 'object' || !(property in error)) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user