(
emitter: NodeJS.EventEmitter,
label: string,
options: StreamErrorHandlerOptions = {}
)
| 42 | } |
| 43 | |
| 44 | export function attachStreamErrorHandler( |
| 45 | emitter: NodeJS.EventEmitter, |
| 46 | label: string, |
| 47 | options: StreamErrorHandlerOptions = {} |
| 48 | ): () => void { |
| 49 | const handler = (error: unknown) => { |
| 50 | const normalized = normalizeError(error); |
| 51 | const info: StreamErrorInfo = { |
| 52 | label, |
| 53 | code: getErrorCode(error), |
| 54 | message: normalized.message, |
| 55 | }; |
| 56 | |
| 57 | if (isIgnorableStreamError(error)) { |
| 58 | options.logger?.debug("Ignored stream error", info, normalized); |
| 59 | options.onIgnorable?.(normalized, info); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | options.logger?.warn("Stream error", info, normalized); |
| 64 | options.onUnexpected?.(normalized, info); |
| 65 | }; |
| 66 | |
| 67 | emitter.on("error", handler); |
| 68 | |
| 69 | return () => { |
| 70 | emitter.removeListener("error", handler); |
| 71 | }; |
| 72 | } |
no test coverage detected