The error type.
The error message.
The original error object.
Optionalcontext: Record<string, unknown>Optional metadata to include with the error.
Optionalcode: stringOptional error code for categorization.
OptionalrecoveryAction: ErrorRecoveryActionOptional recovery action hint for the UI.
OptionalrecoveryMessage: stringOptional user-friendly recovery instruction.
The constructed AppError object.
export function captureError(
type: ErrorType,
message: string,
originalError: unknown,
context?: Record<string, unknown>,
code?: string,
recoveryAction?: ErrorRecoveryAction,
recoveryMessage?: string,
): AppError {
const appError = createError(
type,
message,
originalError,
code,
recoveryAction,
recoveryMessage,
);
// Only capture to Sentry in production or when SENTRY_DSN is configured
if (
globalThis.window !== undefined &&
(import.meta.env.MODE === "production" || import.meta.env.VITE_SENTRY_DSN)
) {
// Dynamic import to avoid hard dependency on Sentry
import("@sentry/electron/renderer")
.then((Sentry) => {
Sentry.captureException(originalError, {
tags: {
errorType: type,
errorCode: code || "UNKNOWN",
recoveryAction: recoveryAction || "none",
},
contexts: context
? {
app: context,
}
: undefined,
});
})
.catch((err) => {
console.debug(
"[ErrorHandling] Failed to capture error to Sentry:",
err,
);
});
}
return appError;
}
Captures an error to Sentry for monitoring and analysis in production. Wraps error creation with Sentry integration, sending errors when configured.