From 5eaaa45dc50030352d282a624bc5814707d66442 Mon Sep 17 00:00:00 2001 From: Owen Pearson Date: Tue, 21 Sep 2021 11:36:26 +0100 Subject: [PATCH 1/3] XHRRequest: only parse response as errorinfo if x-ably-errorcode present --- browser/lib/transport/xhrrequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/lib/transport/xhrrequest.js b/browser/lib/transport/xhrrequest.js index eb69e6d48a..a2d0b6de1b 100644 --- a/browser/lib/transport/xhrrequest.js +++ b/browser/lib/transport/xhrrequest.js @@ -221,7 +221,7 @@ var XHRRequest = (function() { return; } - var err = responseBody.error && ErrorInfo.fromValues(responseBody.error); + var err = headers['x-ably-errorcode'] && responseBody.error && ErrorInfo.fromValues(responseBody.error); if(!err) { err = new ErrorInfo('Error response received from server: ' + statusCode + ' body was: ' + Utils.inspect(responseBody), null, statusCode); } From 5e5d5ff10891b08c7a988dbadaf48c0450a8426e Mon Sep 17 00:00:00 2001 From: Owen Pearson Date: Tue, 21 Sep 2021 11:37:03 +0100 Subject: [PATCH 2/3] add test for authUrl custom err response --- spec/realtime/auth.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/realtime/auth.test.js b/spec/realtime/auth.test.js index 574384c2dd..2e954630f2 100644 --- a/spec/realtime/auth.test.js +++ b/spec/realtime/auth.test.js @@ -602,6 +602,17 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async ) ); /* expectFailed: */ + /* 403 should cause connection to fail even with an external error response */ + it( + 'authUrl_403_custom_error', + authCallback_failures( + { + authUrl: echoServer + '/respondwith?status=403&type=json&body={"error"={"some_custom": "error"}}' + }, + true + ) + ); + /* auth endpoints don't envelope, so this won't work with jsonp */ if (helper.bestTransport !== 'jsonp') { it('authUrl_403_previously_active', function (done) { From ed8be2989bc94819f6275b799f4132d44df2f979 Mon Sep 17 00:00:00 2001 From: Owen Pearson Date: Wed, 22 Sep 2021 11:19:05 +0100 Subject: [PATCH 3/3] fix authUrl in custom_error test --- spec/realtime/auth.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/realtime/auth.test.js b/spec/realtime/auth.test.js index 2e954630f2..6b435d8054 100644 --- a/spec/realtime/auth.test.js +++ b/spec/realtime/auth.test.js @@ -607,7 +607,7 @@ define(['ably', 'shared_helper', 'async', 'chai'], function (Ably, helper, async 'authUrl_403_custom_error', authCallback_failures( { - authUrl: echoServer + '/respondwith?status=403&type=json&body={"error"={"some_custom": "error"}}' + authUrl: echoServer + '/?status=403&type=json&body=' + encodeURIComponent(JSON.stringify({error: {some_custom: "error"}})) }, true )