summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs/unit-http/unit.cpp
diff options
context:
space:
mode:
authorAlexander Borisov <alexander.borisov@nginx.com>2018-12-19 15:56:37 +0300
committerAlexander Borisov <alexander.borisov@nginx.com>2018-12-19 15:56:37 +0300
commitab461437b5714d75e710febe3b44da49ebfe83fc (patch)
tree05abdc488685043f88d59d73109e61684b52e953 /src/nodejs/unit-http/unit.cpp
parentdcf51274ce0953e577fbfffd81afb592319a2267 (diff)
downloadunit-ab461437b5714d75e710febe3b44da49ebfe83fc.tar.gz
unit-ab461437b5714d75e710febe3b44da49ebfe83fc.tar.bz2
Node.js: checking for exception after running JS code from C++.
Diffstat (limited to 'src/nodejs/unit-http/unit.cpp')
-rw-r--r--src/nodejs/unit-http/unit.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp
index 36bc98db..60b0412a 100644
--- a/src/nodejs/unit-http/unit.cpp
+++ b/src/nodejs/unit-http/unit.cpp
@@ -277,7 +277,7 @@ void
Unit::request_handler(nxt_unit_request_info_t *req)
{
Unit *obj;
- napi_value socket, request, response, global, server_obj;
+ napi_value socket, request, response, global, server_obj, except;
napi_value emit_events, events_res, async_name, resource_object;
napi_status status;
napi_async_context async_context;
@@ -372,8 +372,25 @@ Unit::request_handler(nxt_unit_request_info_t *req)
status = napi_make_callback(obj->env_, async_context, server_obj,
emit_events, 3, events_args, &events_res);
if (status != napi_ok) {
- napi_throw_error(obj->env_, NULL, "Failed to make callback");
- return;
+ if (status != napi_pending_exception) {
+ napi_throw_error(obj->env_, NULL, "Failed to make callback");
+ return;
+ }
+
+ status = napi_get_and_clear_last_exception(obj->env_, &except);
+ if (status != napi_ok) {
+ napi_throw_error(obj->env_, NULL,
+ "Failed to get and clear last exception");
+ return;
+ }
+
+ /* Logging a description of the error and call stack. */
+ status = napi_fatal_exception(obj->env_, except);
+ if (status != napi_ok) {
+ napi_throw_error(obj->env_, NULL, "Failed to call "
+ "napi_fatal_exception() function");
+ return;
+ }
}
status = napi_close_callback_scope(obj->env_, async_scope);