0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

feat(core): report oidc exceptions to the appInsights (#5978)

report oidc exceptions to the appInsights
This commit is contained in:
simeng-li 2024-06-03 18:58:56 +08:00 committed by GitHub
parent 0748a22efb
commit a495ab00ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,3 +1,4 @@
import { appInsights } from '@logto/app-insights/node';
import { condObject, isObject } from '@silverhand/essentials';
import i18next from 'i18next';
import type { Middleware } from 'koa';
@ -6,6 +7,7 @@ import { z } from 'zod';
import { EnvSet } from '#src/env-set/index.js';
import { getConsoleLogFromContext } from '#src/utils/console.js';
import { buildAppInsightsTelemetry } from '#src/utils/request.js';
/**
* Supplementary URIs for oidc-provider errors.
@ -88,6 +90,9 @@ export default function koaOidcErrorHandler<StateT, ContextT>(): Middleware<Stat
throw error;
}
// Report oidc exceptions to ApplicationInsights
void appInsights.trackException(error, buildAppInsightsTelemetry(ctx));
// Mimic oidc-provider's error handling, thus we can use the unified logic below.
// See https://github.com/panva/node-oidc-provider/blob/37d0a6cfb3c618141a44cbb904ce45659438f821/lib/shared/error_handler.js
ctx.status = error.statusCode || 500;