Skip to content

Commit

Permalink
chore: move error creation in handler function
Browse files Browse the repository at this point in the history
  • Loading branch information
BridgeAR committed May 25, 2017
1 parent 140e621 commit 4d86647
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ function parseError (parser) {
* @param {number} type
* @returns {undefined}
*/
function handleError (parser, error) {
function handleError (parser, type) {
const err = new ParserError(
'Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte',
JSON.stringify(parser.buffer),
parser.offset
)
parser.buffer = null
parser.returnFatalError(error)
parser.returnFatalError(err)
}

/**
Expand Down Expand Up @@ -296,11 +301,7 @@ function parseType (parser, type) {
case 45:
return parseError(parser)
default:
return handleError(parser, new ParserError(
'Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte',
JSON.stringify(parser.buffer),
parser.offset
))
return handleError(parser, type)
}
}

Expand Down

0 comments on commit 4d86647

Please sign in to comment.