mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-01-01 01:27:54 +01:00
Merge pull request #104 from michielmulders/payloadmessage
#31 Solved throw payload message at baserequest
This commit is contained in:
commit
922524e2ed
@ -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
|
// 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
|
// See https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch
|
||||||
if (!(res && res.ok)) {
|
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
|
return res
|
||||||
})
|
})
|
||||||
|
@ -7,8 +7,21 @@ import { Connection } from '../../src'
|
|||||||
const API_PATH = 'http://localhost:9984/api/v1/'
|
const API_PATH = 'http://localhost:9984/api/v1/'
|
||||||
const conn = new Connection(API_PATH)
|
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 = {
|
const endpoints = {
|
||||||
'blocks': 'blocks',
|
'blocks': 'blocks',
|
||||||
'blocksDetail': 'blocks/%(blockId)s',
|
'blocksDetail': 'blocks/%(blockId)s',
|
||||||
|
Loading…
Reference in New Issue
Block a user