Skip to content

Commit aa83b5e

Browse files
committed
pg: Re-export DatabaseError from 'pg-protocol'
Before, users would have to import DatabaseError from 'pg-protocol'. If there are multiple versions of 'pg-protocol', you might end up using the wrong one. Closes brianc#2378
1 parent 3f3f1a7 commit aa83b5e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: packages/pg/lib/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Client = require('./client')
44
var defaults = require('./defaults')
55
var Connection = require('./connection')
66
var Pool = require('pg-pool')
7+
const { DatabaseError } = require('pg-protocol')
78

89
const poolFactory = (Client) => {
910
return class BoundPool extends Pool {
@@ -21,6 +22,7 @@ var PG = function (clientConstructor) {
2122
this._pools = []
2223
this.Connection = Connection
2324
this.types = require('pg-types')
25+
this.DatabaseError = DatabaseError
2426
}
2527

2628
if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {

Diff for: packages/pg/test/integration/client/error-handling-tests.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ suite.test('non-query error with callback', function (done) {
151151
})
152152
client.connect(
153153
assert.calls(function (error, client) {
154-
assert(error instanceof Error)
154+
assert(error instanceof pg.DatabaseError)
155155
done()
156156
})
157157
)
@@ -182,7 +182,7 @@ suite.test('when connecting to an invalid host with callback', function (done) {
182182
assert.fail('unexpected error event when connecting')
183183
})
184184
client.connect(function (error, client) {
185-
assert(error instanceof Error)
185+
assert(error instanceof pg.DatabaseError)
186186
done()
187187
})
188188
})
@@ -202,7 +202,7 @@ suite.test('non-query error', function (done) {
202202
user: 'asldkfjsadlfkj',
203203
})
204204
client.connect().catch((e) => {
205-
assert(e instanceof Error)
205+
assert(e instanceof pg.DatabaseError)
206206
done()
207207
})
208208
})

0 commit comments

Comments
 (0)