diff --git a/src/bindings/js/node/src/infer_request.cpp b/src/bindings/js/node/src/infer_request.cpp index a1bc3a5daa8..553fb27dded 100644 --- a/src/bindings/js/node/src/infer_request.cpp +++ b/src/bindings/js/node/src/infer_request.cpp @@ -152,29 +152,23 @@ Napi::Value InferRequestWrap::get_output_tensors(const Napi::CallbackInfo& info) } Napi::Value InferRequestWrap::infer_dispatch(const Napi::CallbackInfo& info) { - if (info.Length() == 0) - _infer_request.infer(); - else if (info.Length() == 1 && info[0].IsTypedArray()) { - reportError(info.Env(), "TypedArray cannot be passed directly into infer() method."); - return info.Env().Null(); - } else if (info.Length() == 1 && info[0].IsArray()) { - try { + try { + if (info.Length() == 0) + _infer_request.infer(); + else if (info.Length() == 1 && info[0].IsTypedArray()) { + OPENVINO_THROW("TypedArray cannot be passed directly into infer() method."); + } else if (info.Length() == 1 && info[0].IsArray()) { infer(info[0].As()); - } catch (std::exception& e) { - reportError(info.Env(), e.what()); - return info.Env().Null(); - } - } else if (info.Length() == 1 && info[0].IsObject()) { - try { + } else if (info.Length() == 1 && info[0].IsObject()) { infer(info[0].As()); - } catch (std::exception& e) { - reportError(info.Env(), e.what()); - return info.Env().Null(); + } else { + OPENVINO_THROW("Infer method takes as an argument an array or an object."); } - } else { - reportError(info.Env(), "Infer method takes as an argument an array or an object."); + return get_output_tensors(info); + } catch (std::exception& e) { + reportError(info.Env(), e.what()); + return info.Env().Undefined(); } - return get_output_tensors(info); } void InferRequestWrap::infer(const Napi::Array& inputs) { diff --git a/src/bindings/js/node/tests/infer_request.test.js b/src/bindings/js/node/tests/infer_request.test.js index 27543233f57..d074b53afc7 100644 --- a/src/bindings/js/node/tests/infer_request.test.js +++ b/src/bindings/js/node/tests/infer_request.test.js @@ -55,7 +55,7 @@ describe('InferRequest', () => { it('Test infer(TypedArray) throws', () => { assert.throws( () => inferRequest.infer(tensorData), - {message: 'TypedArray cannot be passed directly into infer() method.'}); + {message: /TypedArray cannot be passed directly into infer\(\) method./}); }); const buffer = new ArrayBuffer(tensorData.length);