Skip to content

Commit 50896aa

Browse files
committed
refactor(javascript): MessageProcessor abstraction added and implemented in catcher event processing pipeline
- MessageProcessor interface and MessageHint type - BrowserMessageProcessor, BreadcrumbsMessageProcessor, ConsoleCatcherMessageProcessor, DebugMessageProcessor - replaced inline addon logic with sequential MessageProcessor pipeline
1 parent 8df48ec commit 50896aa

13 files changed

+418
-193
lines changed

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export { buildElementSelector } from './utils/selector';
1313
export { EventRejectedError } from './errors';
1414
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
1515
export type { BreadcrumbStore, BreadcrumbsAPI, BreadcrumbHint, BreadcrumbInput } from './breadcrumbs/breadcrumb-store';
16+
export type { MessageHint, MessageProcessor } from './messages/message-processor'
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Breadcrumb, CatcherMessagePayload, CatcherMessageType } from '@hawk.so/types';
2+
3+
/**
4+
* Snapshot of event context captured synchronously at error time,
5+
* before any processing.
6+
*/
7+
export interface MessageHint {
8+
/**
9+
* Original caught error.
10+
*/
11+
error?: Error | string;
12+
13+
/**
14+
* Breadcrumbs captured at error time.
15+
*/
16+
breadcrumbs?: Breadcrumb[];
17+
}
18+
19+
/**
20+
* Single step in message processing pipeline before message is sent.
21+
*
22+
* @typeParam T - catcher message type this processor handles
23+
*/
24+
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
25+
/**
26+
* Handles input message. May mutate or replace it.
27+
*
28+
* @param payload - processed event message payload
29+
* @param hint - additional context about original error
30+
* @returns modified payload, or `null` to drop event
31+
*/
32+
apply(
33+
payload: CatcherMessagePayload<T>,
34+
hint?: MessageHint,
35+
): CatcherMessagePayload<T> | null
36+
}

packages/javascript/src/addons/userAgentInfo.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)