Skip to content

Commit

Permalink
feat(connection manager): proxy error event
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 16, 2019
1 parent d5a52c0 commit 5919bd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions adonis-typings/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ declare module '@ioc:Adonis/Addons/Database' {
*/
on (event: 'disconnect', callback: (connection: ConnectionContract) => void): this

/**
* When error is received on a given connection
*/
on (event: 'error', callback: (connection: ConnectionContract, error: Error) => void): this

/**
* Add a new connection to the list of managed connection. You must call
* connect seperately to instantiate a connection instance
Expand Down
7 changes: 7 additions & 0 deletions src/Connection/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export class ConnectionManager extends EventEmitter implements ConnectionManager
this.emit('connect', $connection)
internalConnection.state = 'open'
})

/**
* Listens for error event to proxy it to the client
*/
connection.on('error', ($connection, error) => {
this.emit('error', $connection, error)
})
}

/**
Expand Down

0 comments on commit 5919bd3

Please sign in to comment.