From 9fde58721145d270b7315540387f862fa167a422 Mon Sep 17 00:00:00 2001 From: blagoev Date: Mon, 2 Oct 2017 13:29:53 +0300 Subject: [PATCH] throw Error object always --- lib/browser/rpc.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/browser/rpc.js b/lib/browser/rpc.js index 4bcb755d..bd0d6eed 100644 --- a/lib/browser/rpc.js +++ b/lib/browser/rpc.js @@ -247,13 +247,16 @@ function sendRequest(command, data, host = sessionHost) { error = error.replace(/^[a-z]+: /i, ''); } else if (error.type && error.type == 'dict') { - let responseError = deserialize_json_value(error); + const responseError = deserialize_json_value(error); + let responeMessage; if (response.message && response.message !== '') { // Remove the type prefix from the error message (e.g. "Error: "). - responseError.message = response.message.replace(/^[a-z]+: /i, ''); + responeMessage = response.message.replace(/^[a-z]+: /i, ''); } - - throw responseError; + + const exceptionToReport = new Error(responeMessage); + Object.assign(exceptionToReport, responseError); + throw exceptionToReport; } throw new Error(error || `Invalid response for "${command}"`);