feat(messaging): `error` ServerEvent support
MODIFY
packages/messaging/src/server/messaging.server.events.ts
packages/messaging/src/server/messaging.server.events.ts
@@ -3,6 +3,7 @@ import { createEvent, EventsUnion, Event } from '@marblejs/core';
export enum ServerEventType {
LISTENING = 'listening',
CLOSE = 'close',
+ ERROR = 'error',
}
export const ServerEvent = {
@@ -13,6 +14,10 @@ export const ServerEvent = {
close: createEvent(
ServerEventType.CLOSE,
),
+ error: createEvent(
+ ServerEventType.ERROR,
+ (error: Error) => ({ error }),
+ )
};
export type AllServerEvents = EventsUnion<typeof ServerEvent>;
@@ -24,3 +29,7 @@ export function isListeningEvent(event: Event): event is ReturnType<typeof Serve
export function isCloseEvent(event: Event): event is ReturnType<typeof ServerEvent.close> {
return event.type === ServerEventType.CLOSE;
}
+
+export function isErrorEvent(event: Event): event is ReturnType<typeof ServerEvent.error> {
+ return event.type === ServerEventType.ERROR;
+}

MODIFY
packages/messaging/src/server/messaging.server.listener.ts
packages/messaging/src/server/messaging.server.listener.ts
@@ -88,6 +88,10 @@ export const messagingListener = (config: MessagingListenerConfig = {}) => {
.pipe(take(1))
.subscribe(() => serverEventsSubject.next(ServerEvent.close()));
+ conn.error$
+ .pipe(takeUntil(conn.close$))
+ .subscribe(error => serverEventsSubject.next(ServerEvent.error(error)));
+
effectsSub = subscribeEffects(message$);
};

feat(messaging): `error` ServerEvent support