Skip to content

Commit 4d86647

Browse files
committed
chore: move error creation in handler function
1 parent 140e621 commit 4d86647

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/parser.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,14 @@ function parseError (parser) {
186186
* @param {number} type
187187
* @returns {undefined}
188188
*/
189-
function handleError (parser, error) {
189+
function handleError (parser, type) {
190+
const err = new ParserError(
191+
'Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte',
192+
JSON.stringify(parser.buffer),
193+
parser.offset
194+
)
190195
parser.buffer = null
191-
parser.returnFatalError(error)
196+
parser.returnFatalError(err)
192197
}
193198

194199
/**
@@ -296,11 +301,7 @@ function parseType (parser, type) {
296301
case 45:
297302
return parseError(parser)
298303
default:
299-
return handleError(parser, new ParserError(
300-
'Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte',
301-
JSON.stringify(parser.buffer),
302-
parser.offset
303-
))
304+
return handleError(parser, type)
304305
}
305306
}
306307

0 commit comments

Comments
 (0)