Skip to content

Commit

Permalink
Merge pull request #104 from michielmulders/payloadmessage
Browse files Browse the repository at this point in the history
#31 Solved throw payload message at baserequest
  • Loading branch information
jernejpregelj committed Oct 6, 2017
2 parents 1d58986 + f4333a9 commit 922524e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/baseRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
15 changes: 14 additions & 1 deletion test/connection/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 922524e

Please sign in to comment.