Skip to content

Commit b56daf4

Browse files
committed
Fix errors during connection
1 parent 447084f commit b56daf4

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

.eslintrc.json

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"node": true,
55
"es6": true
66
},
7-
"parser": "babel-eslint",
87
"parserOptions": {
98
"ecmaVersion": 9,
109
"sourceType": "module"

lib/backend.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function Backend({
1313
onready,
1414
transform,
1515
onnotice,
16-
onnotify
16+
onnotify,
17+
error
1718
}) {
1819
let rows = 0
1920

@@ -119,7 +120,9 @@ function Backend({
119120
function CopyData() { /* No handling needed until implemented */ }
120121

121122
function ErrorResponse(x) {
122-
backend.error = errors.generic(error(x))
123+
backend.query
124+
? (backend.error = errors.generic(parseError(x)))
125+
: error(errors.generic(parseError(x)))
123126
}
124127

125128
/* c8 ignore next */
@@ -142,8 +145,8 @@ function Backend({
142145

143146
function NoticeResponse(x) {
144147
onnotice
145-
? onnotice(error(x))
146-
: console.log(error(x)) // eslint-disable-line
148+
? onnotice(parseError(x))
149+
: console.log(parseError(x)) // eslint-disable-line
147150
}
148151

149152
function NoData() { /* No handling needed */ }
@@ -153,7 +156,7 @@ function Backend({
153156
try {
154157
type !== 0 && onauth(type, x)
155158
} catch (err) {
156-
backend.error = err
159+
error(err)
157160
}
158161
}
159162

@@ -212,12 +215,12 @@ function Backend({
212215
backend.error = errors.notSupported('CopyBothResponse')
213216
}
214217

215-
function ReadyForQuery(x) {
218+
function ReadyForQuery() {
216219
onready(backend.error)
217220
}
218221
}
219222

220-
function error(x) {
223+
function parseError(x) {
221224
const error = {}
222225
let start = 5
223226
for (let i = 5; i < x.length - 1; i++) {

lib/connection.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function Connection(options = {}) {
4444
onnotify,
4545
onnotice,
4646
onready,
47-
onauth
47+
onauth,
48+
error
4849
})
4950

5051
return connection
@@ -131,7 +132,7 @@ function Connection(options = {}) {
131132
? backend.query.result.count
132133
: backend.query.result))
133134

134-
backend.error = null
135+
backend.query = backend.error = null
135136
timeout && queries.length === 0 && idle()
136137

137138
if (queries.length === 0 && ended)

0 commit comments

Comments
 (0)