Skip to content

Commit ed1da69

Browse files
committed
feature: added messageProcessors parameter in HawkInitialSettings
1 parent c3ffcae commit ed1da69

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/core/src/messages/message-processor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ export interface ErrorSnapshot {
4444
*/
4545
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
4646
/**
47-
* Handles input message. May mutate or replace it.
47+
* Handles input message. May mutate, replace or drop it.
48+
*
49+
* Dropped message won't be sent.
4850
*
4951
* @param payload - processed event message payload with partially-built addons
5052
* @param snapshot - additional context with original error
51-
* @returns modified payload, or `null` to drop event
53+
* @returns modified payload, or `null` to drop message
5254
*/
5355
apply(
5456
payload: ProcessingPayload<T>,

packages/javascript/src/catcher.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ export default class Catcher {
217217
this.messageProcessors.push(new DebugAddonMessageProcessor());
218218
}
219219

220+
if (settings.messageProcessors) {
221+
this.messageProcessors.push(...settings.messageProcessors);
222+
}
223+
220224
/**
221225
* Set global handlers
222226
*/

packages/javascript/src/types/hawk-initial-settings.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AffectedUser, EventContext } from '@hawk.so/types';
22
import type { HawkJavaScriptEvent } from './event';
3-
import type { Transport } from '@hawk.so/core';
3+
import type { MessageProcessor, Transport } from '@hawk.so/core';
44
import type { BreadcrumbsOptions } from '../addons/breadcrumbs';
55

66
/**
@@ -98,4 +98,11 @@ export interface HawkInitialSettings {
9898
* If not provided, default WebSocket transport is used.
9999
*/
100100
transport?: Transport;
101+
102+
/**
103+
* Custom message processors.
104+
* Used to prepare event message before send.
105+
* May modify original event payload or return null to drop it.
106+
*/
107+
messageProcessors?: MessageProcessor<'errors/javascript'>[];
101108
}

0 commit comments

Comments
 (0)