@@ -81,6 +81,7 @@ export interface PostgresAdapterOptions {
8181 channelPrefix : string ;
8282 /**
8383 * The name of the table for payloads over the 8000 bytes limit or containing binary data
84+ * @default "socket_io_attachments"
8485 */
8586 tableName : string ;
8687 /**
@@ -108,6 +109,12 @@ export interface PostgresAdapterOptions {
108109 * @default 30000
109110 */
110111 cleanupInterval : number ;
112+ /**
113+ * Handler for errors. If undefined, the errors will be simply logged.
114+ *
115+ * @default undefined
116+ */
117+ errorHandler : ( err : Error ) => void ;
111118}
112119
113120/**
@@ -136,6 +143,7 @@ export class PostgresAdapter extends Adapter {
136143 public heartbeatTimeout : number ;
137144 public payloadThreshold : number ;
138145 public cleanupInterval : number ;
146+ public errorHandler : ( err : Error ) => void ;
139147
140148 private readonly pool : Pool ;
141149 private client : any ;
@@ -169,6 +177,8 @@ export class PostgresAdapter extends Adapter {
169177 this . heartbeatTimeout = opts . heartbeatTimeout || 10000 ;
170178 this . payloadThreshold = opts . payloadThreshold || 8000 ;
171179 this . cleanupInterval = opts . cleanupInterval || 30000 ;
180+ const defaultErrorHandler = ( err : Error ) => debug ( err ) ;
181+ this . errorHandler = opts . errorHandler || defaultErrorHandler ;
172182
173183 this . initSubscription ( ) ;
174184 this . publish ( {
@@ -203,7 +213,7 @@ export class PostgresAdapter extends Adapter {
203213 try {
204214 await this . onEvent ( msg . payload ) ;
205215 } catch ( err ) {
206- this . emit ( "error" , err ) ;
216+ this . errorHandler ( err ) ;
207217 }
208218 } ) ;
209219
@@ -218,7 +228,7 @@ export class PostgresAdapter extends Adapter {
218228
219229 this . client = client ;
220230 } catch ( err ) {
221- this . emit ( "error" , err ) ;
231+ this . errorHandler ( err ) ;
222232 debug ( "error while initializing client, scheduling reconnection..." ) ;
223233 this . scheduleReconnection ( ) ;
224234 }
@@ -396,7 +406,7 @@ export class PostgresAdapter extends Adapter {
396406 `DELETE FROM ${ this . tableName } WHERE created_at < now() - interval '${ this . cleanupInterval } milliseconds'`
397407 ) ;
398408 } catch ( err ) {
399- this . emit ( "error" , err ) ;
409+ this . errorHandler ( err ) ;
400410 }
401411 this . scheduleCleanup ( ) ;
402412 } , this . cleanupInterval ) ;
@@ -434,7 +444,7 @@ export class PostgresAdapter extends Adapter {
434444
435445 this . scheduleHeartbeat ( ) ;
436446 } catch ( err ) {
437- this . emit ( "error" , err ) ;
447+ this . errorHandler ( err ) ;
438448 }
439449 }
440450
0 commit comments