@ministryofjustice/fb-jwt-client-node
Advanced tools
Comparing version 0.0.23-2 to 0.0.23-3
@@ -244,3 +244,3 @@ const prometheus = require('prom-client') | ||
if (hasData && !searchParams) { | ||
requestOptions.body = json | ||
requestOptions.body = JSON.stringify(json) | ||
} | ||
@@ -352,8 +352,16 @@ if (searchParams && hasData) { | ||
(response, retryWithMergedOptions) => { | ||
let body = response.body | ||
try { | ||
body = JSON.parse(body) | ||
} catch (e) { | ||
body = {} | ||
} | ||
response.body = body | ||
console.log('body', body) | ||
console.log('response.body', response.body) | ||
if (response.statusCode >= 400) { | ||
const {statusCode, statusMessage, body, retryCount, stack} = response | ||
const {statusCode, statusMessage, retryCount, stack} = response | ||
const error = { | ||
statusCode, | ||
statusMessage, | ||
body, | ||
retryCount, | ||
@@ -364,8 +372,2 @@ stack | ||
} | ||
try { | ||
response.body = JSON.parse(response.body) | ||
} catch (e) { | ||
console.log('CLIENT RESPONSE ERROR', response.body, e) // eslint-disable-line no-console | ||
response.body = {} | ||
} | ||
requestMetricsEnd(getResponseLabels(response)) | ||
@@ -372,0 +374,0 @@ return response |
@@ -117,3 +117,3 @@ const test = require('tape') | ||
headers: {'x-access-token': 'testAccessToken'}, | ||
body: {foo: 'bar'} | ||
body: JSON.stringify({foo: 'bar'}) | ||
// json: true | ||
@@ -273,3 +273,3 @@ }, 'it should set the correct url, headers and json object') | ||
t.equal(callArgs.url, `${microserviceUrl}/user/testUserId`, 'it should call the correct url') | ||
t.deepEqual(callArgs.body, data, 'it should post the correct data') | ||
t.deepEqual(callArgs.body, JSON.stringify(data), 'it should post the correct data') | ||
t.deepEqual(callArgs.headers['x-access-token'], 'accessToken', 'it should add the x-access-token header') | ||
@@ -331,3 +331,3 @@ | ||
.get(url) | ||
.reply(code, response) | ||
.reply(code, JSON.stringify(response)) | ||
@@ -334,0 +334,0 @@ return nockedClient.send('get', {url}) |
{ | ||
"name": "@ministryofjustice/fb-jwt-client-node", | ||
"version": "0.0.23-2", | ||
"version": "0.0.23-3", | ||
"description": "Form Builder JSON Web Token Client (Node)", | ||
@@ -5,0 +5,0 @@ "main": "lib/fb-jwt-client.js", |
55374
1462