mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor: stringify error before report to AppInsights (#3964)
This commit is contained in:
parent
598392a5ec
commit
c3ff23902d
1 changed files with 11 additions and 3 deletions
|
@ -4,10 +4,18 @@ import type { TelemetryClient } from 'applicationinsights';
|
|||
export const normalizeError = (error: unknown) => {
|
||||
const normalized = error instanceof Error ? error : new Error(String(error));
|
||||
|
||||
// Add message if empty otherwise Application Insights will respond 400
|
||||
// and the error will not be recorded.
|
||||
/**
|
||||
* - Ensure the message if not empty otherwise Application Insights will respond 400
|
||||
* and the error will not be recorded.
|
||||
* - We stringify error object here since other error properties won't show on the
|
||||
* ApplicationInsights details page.
|
||||
*/
|
||||
// eslint-disable-next-line @silverhand/fp/no-mutation
|
||||
normalized.message ||= 'Error occurred.';
|
||||
normalized.message = JSON.stringify(
|
||||
error,
|
||||
// ApplicationInsights shows call stack, no need to stringify
|
||||
Object.getOwnPropertyNames(error).filter((value) => value !== 'stack')
|
||||
);
|
||||
|
||||
return normalized;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue