diff --git a/src/baseRequest.js b/src/baseRequest.js index e75e92a..90ce3b2 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -74,7 +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 res + const errorObject = { + message: 'HTTP Error: Requested page not reachable', + status: `${res.status} ${res.statusText}`, + requestURI: res.url + } + throw errorObject } return res }) diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 8e7e495..435e38b 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -7,8 +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 => { + 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/transactions/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',