From 6c01d375768d46d16486449835e230595dfa9412 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Tue, 26 Sep 2017 16:05:25 +0200 Subject: [PATCH 1/7] Solved throw payload message at baserequest --- src/baseRequest.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/baseRequest.js b/src/baseRequest.js index e75e92a..0b5a829 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -74,7 +74,11 @@ export default function baseRequest(url, { jsonBody, query, urlTemplateSpec, ... // If status is not a 2xx (based on Response.ok), assume it's an error // See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch if (!(res && res.ok)) { - throw res + throw { + message: "HTTP Error: Couldn't reach requested webpage", + status: res.status + " " + res.statusText, + requestURI: res.url + } } return res }) From 823d340d6102edd166c92c8f499086efb90c3f15 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Tue, 26 Sep 2017 16:19:36 +0200 Subject: [PATCH 2/7] Updated errorObject to match TravisCI criteria --- src/baseRequest.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/baseRequest.js b/src/baseRequest.js index 0b5a829..3f53370 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -74,11 +74,12 @@ export default function baseRequest(url, { jsonBody, query, urlTemplateSpec, ... // If status is not a 2xx (based on Response.ok), assume it's an error // See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch if (!(res && res.ok)) { - throw { - message: "HTTP Error: Couldn't reach requested webpage", - status: res.status + " " + res.statusText, + let errorObject = { + message: 'HTTP Error: Requested page not reachable', + status: '${res.status} ${res.statusText}', requestURI: res.url } + throw errorObject } return res }) From 42c037c6aca8010fa4195150b6818021a9608bc5 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Tue, 26 Sep 2017 16:25:07 +0200 Subject: [PATCH 3/7] Trying to match TravisCI Criteria --- src/baseRequest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/baseRequest.js b/src/baseRequest.js index 3f53370..99d7fc4 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -74,9 +74,9 @@ export default function baseRequest(url, { jsonBody, query, urlTemplateSpec, ... // If status is not a 2xx (based on Response.ok), assume it's an error // See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch if (!(res && res.ok)) { - let errorObject = { + const errorObject = { message: 'HTTP Error: Requested page not reachable', - status: '${res.status} ${res.statusText}', + status: (res.status) + ' ' + (res.statusText), requestURI: res.url } throw errorObject From ce9e88bac3ccf80911774f4b6e2cac8971470b31 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Tue, 26 Sep 2017 16:29:52 +0200 Subject: [PATCH 4/7] Fixed for TravisCI --- src/baseRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/baseRequest.js b/src/baseRequest.js index 99d7fc4..90ce3b2 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -76,7 +76,7 @@ export default function baseRequest(url, { jsonBody, query, urlTemplateSpec, ... if (!(res && res.ok)) { const errorObject = { message: 'HTTP Error: Requested page not reachable', - status: (res.status) + ' ' + (res.statusText), + status: `${res.status} ${res.statusText}`, requestURI: res.url } throw errorObject From f82cbd652645a9191968e5cc94ae7fec38e97f21 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Wed, 27 Sep 2017 15:37:49 +0200 Subject: [PATCH 5/7] Writing test for baserequest --- test/connection/test_connection.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 8e7e495..83a82b3 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -7,6 +7,16 @@ import { Connection } from '../../src' const API_PATH = 'http://localhost:9984/api/v1/' const conn = new Connection(API_PATH) +test('payload thrown at incorrect API_PATH', t => { + const path = 'http://localhost:9984/api/wrong/' + const conn = new Connection(path) + const target = { + message: 'HTTP Error: Requested page not reachable', + status: '404 NOT FOUND', + requestURI: 'http://localhost:9984/api/wrong/transactionId' + } + t.deepEqual(target, conn.getTransaction("transactionId")) +}) test('generate API URLS', t => { const endpoints = { From b77d2960695f218b66c87526760bd1157e3ceec2 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Wed, 27 Sep 2017 15:38:52 +0200 Subject: [PATCH 6/7] Writing test for baserequest --- test/connection/test_connection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 83a82b3..5c16baa 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -9,13 +9,13 @@ const conn = new Connection(API_PATH) test('payload thrown at incorrect API_PATH', t => { const path = 'http://localhost:9984/api/wrong/' - const conn = new Connection(path) + const connection = new Connection(path) const target = { message: 'HTTP Error: Requested page not reachable', status: '404 NOT FOUND', requestURI: 'http://localhost:9984/api/wrong/transactionId' } - t.deepEqual(target, conn.getTransaction("transactionId")) + t.deepEqual(target, connection.getTransaction('transactionId')) }) test('generate API URLS', t => { From f4333a92c1cb0f24289fa16bac6a428784e32fe2 Mon Sep 17 00:00:00 2001 From: michielmulders Date: Sat, 30 Sep 2017 19:18:50 +0200 Subject: [PATCH 7/7] Test added for testing payload thrown at incorrect API_PATH --- test/connection/test_connection.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 5c16baa..435e38b 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -7,18 +7,21 @@ import { Connection } from '../../src' const API_PATH = 'http://localhost:9984/api/v1/' const conn = new Connection(API_PATH) -test('payload thrown at incorrect API_PATH', t => { +test('Payload thrown at incorrect API_PATH', t => { const path = 'http://localhost:9984/api/wrong/' const connection = new Connection(path) const target = { message: 'HTTP Error: Requested page not reachable', status: '404 NOT FOUND', - requestURI: 'http://localhost:9984/api/wrong/transactionId' + requestURI: 'http://localhost:9984/api/wrong/transactions/transactionId' } - t.deepEqual(target, connection.getTransaction('transactionId')) + connection.getTransaction('transactionId') + .catch(error => { + t.deepEqual(target, error) + }) }) -test('generate API URLS', t => { +test('Generate API URLS', t => { const endpoints = { 'blocks': 'blocks', 'blocksDetail': 'blocks/%(blockId)s',