diff --git a/lib/jsonwp-proxy/proxy.js b/lib/jsonwp-proxy/proxy.js index a458a286a..b991c827d 100644 --- a/lib/jsonwp-proxy/proxy.js +++ b/lib/jsonwp-proxy/proxy.js @@ -129,7 +129,7 @@ class JWProxy { if (_.includes(statusCodesWithRes, response.statusCode)) { if (response.statusCode === 200 && resBody.status === 0) { return resBody.value; - } else if (response.statusCode === 200 && _.isUndefined(resBody.status)) { + } else if (response.statusCode === 200) { return resBody; } let message = getSummaryByCode(resBody.status); diff --git a/lib/mjsonwp/mjsonwp.js b/lib/mjsonwp/mjsonwp.js index 7a2d84ac1..889947556 100644 --- a/lib/mjsonwp/mjsonwp.js +++ b/lib/mjsonwp/mjsonwp.js @@ -245,8 +245,8 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) { driverRes = null; } - // assuming everything worked, set up the json response object - httpResBody.status = JSONWP_SUCCESS_STATUS_CODE; + // Response status should be the status set by the driver response. + httpResBody.status = (_.isNil(driverRes) || _.isUndefined(driverRes.status)) ? JSONWP_SUCCESS_STATUS_CODE : driverRes.status; httpResBody.value = driverRes; log.info(`Responding to client with driver.${spec.command}() ` + `result: ${_.truncate(JSON.stringify(driverRes), LOG_OBJ_LENGTH)}`); diff --git a/test/jsonwp-proxy/proxy-specs.js b/test/jsonwp-proxy/proxy-specs.js index 45ab23e45..c45720917 100644 --- a/test/jsonwp-proxy/proxy-specs.js +++ b/test/jsonwp-proxy/proxy-specs.js @@ -134,18 +134,11 @@ describe('proxy', () => { e.value.should.eql({message: 'Invisible element'}); e.status.should.equal(11); }); - it('should throw when a command fails with a 200', async () => { + it('should return response body when a command fails with a 200', async () => { let j = mockProxy({sessionId: '123'}); - let e = null; - try { - await j.command('/element/200/text', 'GET'); - } catch (err) { - e = err; - } - should.exist(e); - e.message.should.contain('Original error: Invisible element'); - e.value.should.eql({message: 'Invisible element'}); - e.status.should.equal(11); + let res = await j.command('/element/200/text', 'GET'); + res.value.should.eql({message: 'Invisible element'}); + res.status.should.eql(11); }); it('should throw when a command fails with a 100', async () => { let j = mockProxy({sessionId: '123'});