File tree Expand file tree Collapse file tree 5 files changed +28
-9
lines changed
Expand file tree Collapse file tree 5 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 44
55### Exports
66
7- * [ Session] ( #session )
8- * [ createSession] ( #createsession%3A-(constructorparameters<typeof-session>)-%3D>-promise<session> )
9- * [ Channel] ( #channel )
10- * [ createChannel] ( #createchannel%3A-(...args%3A-constructorparameters<typeof-channel>)-%3D>-channel )
11- * [ EventBuffer] ( #eventbuffer )
12- * [ createEventBuffer] ( #createeventbuffer-args-constructorparameterstypeof-eventbuffer--eventbuffer )
7+ * [ ` Session ` ] ( #session )
8+ * [ ` createSession ` ] ( #createsession%3A-(constructorparameters<typeof-session>)-%3D>-promise<session> )
9+ * [ ` Channel ` ] ( #channel )
10+ * [ ` createChannel ` ] ( #createchannel%3A-(...args%3A-constructorparameters<typeof-channel>)-%3D>-channel )
11+ * [ ` EventBuffer ` ] ( #eventbuffer )
12+ * [ ` createEventBuffer ` ] ( #createeventbuffer-args-constructorparameterstypeof-eventbuffer--eventbuffer )
13+ * [ ` SseError ` ] ( #sseerror )
1314
1415## Documentation
1516
@@ -69,6 +70,8 @@ If no event name is given, the event name is set to `"message"`.
6970
7071If no event ID is given, the event ID (and thus the [ ` lastId ` property] ( #session%23lastid%3A-string ) ) is set to a unique string generated using a [ cryptographic pseudorandom number generator] ( https://nodejs.org/api/crypto.html#cryptorandomuuidoptions ) .
7172
73+ If the session has disconnected, an [ ` SseError ` ] ( #sseerror ) will be thrown.
74+
7275Emits the ` push ` event with the given data, event name and event ID in that order.
7376
7477#### ` Session#stream ` : ` (stream: Readable[, options: object]) => Promise<boolean> `
@@ -321,3 +324,7 @@ Get a copy of the buffer contents.
321324Creates and returns an instance of an [ EventBuffer] ( #eventbuffer ) .
322325
323326Takes the [ same arguments as the EventBuffer class constructor] ( #new-eventbufferoptions-- ) .
327+
328+ ### ` SseError `
329+
330+ Represents an SSE-related error thrown from within Better SSE.
Original file line number Diff line number Diff line change 1+ import { Session , DefaultSessionState } from "./Session" ;
12import { TypedEmitter , EventMap } from "./lib/TypedEmitter" ;
23import { generateId } from "./lib/generateId" ;
3- import { Session , DefaultSessionState } from "./Session " ;
4+ import { SseError } from "./lib/SseError " ;
45
56interface BroadcastOptions <
67 SessionState extends Record < string , unknown > = DefaultSessionState
@@ -77,7 +78,7 @@ class Channel<
7778 }
7879
7980 if ( ! session . isConnected ) {
80- throw new Error ( "Cannot register a non-active session." ) ;
81+ throw new SseError ( "Cannot register a non-active session." ) ;
8182 }
8283
8384 session . once ( "disconnected" , ( ) => {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {createPushFromStream} from "./lib/createPushFromStream";
1111import { createPushFromIterable } from "./lib/createPushFromIterable" ;
1212import { serialize , SerializerFunction } from "./lib/serialize" ;
1313import { sanitize , SanitizerFunction } from "./lib/sanitize" ;
14+ import { SseError } from "./lib/SseError" ;
1415
1516interface SessionOptions
1617 extends Pick < EventBufferOptions , "serializer" | "sanitizer" > {
@@ -353,7 +354,7 @@ class Session<
353354 eventId = generateId ( )
354355 ) : this => {
355356 if ( ! this . isConnected ) {
356- throw new Error ( "Cannot push data to a non-active session." ) ;
357+ throw new SseError ( "Cannot push data to a non-active session." ) ;
357358 }
358359
359360 this . buffer . push ( data , eventName , eventId ) ;
Original file line number Diff line number Diff line change @@ -9,3 +9,5 @@ export * from "./createEventBuffer";
99
1010export type { StreamOptions } from "./lib/createPushFromStream" ;
1111export type { IterateOptions } from "./lib/createPushFromIterable" ;
12+
13+ export * from "./lib/SseError" ;
Original file line number Diff line number Diff line change 1+ class SseError extends Error {
2+ constructor ( message : string ) {
3+ super ( message ) ;
4+ this . message = `better-sse: ${ message } ` ;
5+ }
6+ }
7+
8+ export { SseError } ;
You can’t perform that action at this time.
0 commit comments