diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index f6559ee8b4..a6c77bca16 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -432,9 +432,12 @@ public: // If there was a parse error in one of the callbacks // TODO What if there is an error on EOF? if (!parser->parser_.upgrade && nparsed != len) { + enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_); + Local e = Exception::Error(String::NewSymbol("Parse Error")); Local obj = e->ToObject(); obj->Set(String::NewSymbol("bytesParsed"), nparsed_obj); + obj->Set(String::NewSymbol("code"), String::New(http_errno_name(err))); return scope.Close(e); } else { return scope.Close(nparsed_obj); @@ -455,9 +458,12 @@ public: if (parser->got_exception_) return Local(); if (rv != 0) { + enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_); + Local e = Exception::Error(String::NewSymbol("Parse Error")); Local obj = e->ToObject(); obj->Set(String::NewSymbol("bytesParsed"), Integer::New(0)); + obj->Set(String::NewSymbol("code"), String::New(http_errno_name(err))); return scope.Close(e); } diff --git a/test/simple/test-http-client-parse-error.js b/test/simple/test-http-client-parse-error.js index 1ca7d58f78..91baa4706e 100644 --- a/test/simple/test-http-client-parse-error.js +++ b/test/simple/test-http-client-parse-error.js @@ -48,6 +48,7 @@ srv.listen(common.PORT, '127.0.0.1', function() { console.log('got error from client'); srv.close(); assert.ok(e.message.indexOf('Parse Error') >= 0); + assert.equal(e.code, 'HPE_INVALID_CONSTANT'); parseError = true; }); });