Skip to content

Commit

Permalink
fix: add data to parser error
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Apr 14, 2021
1 parent e9ed5ef commit 7a750ba
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,12 @@ class Client extends Dispatcher {
}

class HTTPParserError extends Error {
constructor (message, code) {
constructor (message, code, data) {
super(message)
Error.captureStackTrace(this, HTTPParserError)
this.name = 'HTTPParserError'
this.code = code ? `HPE_${code}` : undefined
this.data = data.toString()
}
}

Expand Down Expand Up @@ -561,7 +562,7 @@ class Parser {
const len = new Uint8Array(llhttp.exports.memory.buffer, ptr).indexOf(0)
message = Buffer.from(llhttp.exports.memory.buffer, ptr, len).toString()
}
util.destroy(socket, new HTTPParserError(message, constants.ERROR[ret]))
util.destroy(socket, new HTTPParserError(message, constants.ERROR[ret], data))
}
}

Expand Down

0 comments on commit 7a750ba

Please sign in to comment.