-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptionHandler.js
56 lines (50 loc) · 1.44 KB
/
ExceptionHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
COMMAND_BUS_EXCEPTION,
EVENT_BUS_EXCEPTION,
TRANSPORT_SEND_EXCEPTION,
TRIGGER_EXCEPTION
} from './constants.js';
import TriggerExceptionEvent from './events/TriggerExceptionEvent.js';
export default class ExceptionHandler {
/**
* @param {Dispatcher} dispatcher
*/
constructor(dispatcher) {
Object.defineProperty(this, 'dispatcher', { value: dispatcher });
}
/**
* @param {PbjxEvent} event
* @param {string} eventName
* @param {Exception|Error} exception
*/
async onTriggerException(event, eventName, exception) {
const message = event.getMessage();
await this.dispatcher.dispatch(TRIGGER_EXCEPTION, new TriggerExceptionEvent(message, eventName, exception));
}
/**
* @param {BusExceptionEvent} event
*/
async onCommandBusException(event) {
await this.dispatcher.dispatch(COMMAND_BUS_EXCEPTION, event);
}
/**
* @param {BusExceptionEvent} event
*/
async onEventBusException(event) {
await this.dispatcher.dispatch(EVENT_BUS_EXCEPTION, event);
}
/**
* @param {BusExceptionEvent} event
*/
async onRequestBusException(event) {
// because we throw the exception in Pbjx.request
// we don't need to log it, something up the chain will.
//this.dispatcher.dispatch(REQUEST_BUS_EXCEPTION, event);
}
/**
* @param {TransportExceptionEvent} event
*/
async onTransportException(event) {
await this.dispatcher.dispatch(TRANSPORT_SEND_EXCEPTION, event);
}
}