rubik-pact
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -75,3 +75,7 @@ const { Kubik } = require('rubik-main'); | ||
method = method || 'POST'; | ||
if (!method) { | ||
if (body) method = 'POST'; | ||
else method = 'GET'; | ||
} | ||
if (body instanceof FormData) { | ||
@@ -82,15 +86,16 @@ Object.assign(headers, body.getHeaders()); | ||
headers['Content-Type'] = 'application/json'; | ||
} else { | ||
method = 'GET'; | ||
} | ||
const request = await fetch(url, { method, body, headers }); | ||
// console.log(await request.text()); | ||
const result = await request.json(); | ||
const res = await fetch(url, { method, body, headers }); | ||
if (res.status !== 200) { | ||
throw new Error(`Invalid status ${res.status}`); | ||
}; | ||
if (result.status === 'errored') { | ||
throw new PactError(`${get(result, 'errors.0.code')} ${get(result, 'errors.0.description')}`); | ||
const resBody = await res.json(); | ||
if (resBody.status === 'errored') { | ||
throw new PactError(`${get(resBody, 'errors.0.code')} ${get(resBody, 'errors.0.description')}`); | ||
} | ||
return result; | ||
return resBody; | ||
} | ||
@@ -97,0 +102,0 @@ |
{ | ||
"name": "rubik-pact", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Pact Bot Api kubik for the Rubik application system", | ||
@@ -5,0 +5,0 @@ "main": "classes/Pact.js", |
20789
194