|
1 | 1 | import { NotificationLogger } from "./notification-logger"; |
| 2 | +import { AppTelemetry } from "../telemetry"; |
| 3 | +import { RedactableError } from "../../pure/errors"; |
2 | 4 |
|
3 | 5 | export interface ShowAndLogOptions { |
4 | 6 | /** |
@@ -87,3 +89,28 @@ async function internalShowAndLog( |
87 | 89 | void logger.log(fullMessage || message); |
88 | 90 | await fn.bind(logger)(message); |
89 | 91 | } |
| 92 | + |
| 93 | +interface ShowAndLogExceptionOptions extends ShowAndLogOptions { |
| 94 | + /** Custom properties to include in the telemetry report. */ |
| 95 | + extraTelemetryProperties?: { [key: string]: string }; |
| 96 | +} |
| 97 | + |
| 98 | +/** |
| 99 | + * Show an error message, log it to the console, and emit redacted information as telemetry |
| 100 | + * |
| 101 | + * @param logger The logger that will receive the message. |
| 102 | + * @param telemetry The telemetry instance to use for reporting. |
| 103 | + * @param error The error to show. Only redacted information will be included in the telemetry. |
| 104 | + * @param options See individual fields on `ShowAndLogExceptionOptions` type. |
| 105 | + * |
| 106 | + * @return A promise that resolves to the selected item or undefined when being dismissed. |
| 107 | + */ |
| 108 | +export async function showAndLogExceptionWithTelemetry( |
| 109 | + logger: NotificationLogger, |
| 110 | + telemetry: AppTelemetry | undefined, |
| 111 | + error: RedactableError, |
| 112 | + options: ShowAndLogExceptionOptions = {}, |
| 113 | +): Promise<void> { |
| 114 | + telemetry?.sendError(error, options.extraTelemetryProperties); |
| 115 | + return showAndLogErrorMessage(logger, error.fullMessage, options); |
| 116 | +} |
0 commit comments