From 18240193ba421695d984c3d73e88de7e1b324e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 18 Dec 2011 15:55:40 +0100 Subject: [PATCH] Expose http parse error codes Currently http parse errors do not expose the error details available from http_parser. This patch exposes the error code as `err.code`. --- src/node_http_parser.cc | 6 ++++++ test/simple/test-http-client-parse-error.js | 1 + 2 files changed, 7 insertions(+) diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index f6559ee8b4e..a6c77bca16f 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 1ca7d58f787..91baa4706e8 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; }); });