@laboratoria/hubspot
Advanced tools
Comparing version 0.6.0 to 0.7.0
32
index.js
@@ -38,27 +38,15 @@ import https from 'node:https'; | ||
const contentType = (response.headers['content-type'] || '').split(';')[0]; | ||
const isJSON = contentType === 'application/json'; | ||
if (contentType !== 'application/json') { | ||
return reject( | ||
new Error(`Expected content-type to be JSON and got ${contentType}`), | ||
); | ||
} | ||
const respond = (error, json) => { | ||
try { | ||
const json = isJSON ? JSON.parse(responseText) : null; | ||
if (response.statusCode !== 200) { | ||
return reject(Object.assign( | ||
new Error(`Error fetching ${url}: ${response.statusCode}`), | ||
{ json, responseText }, | ||
{ json, responseText, statusCode: response.statusCode }, | ||
)); | ||
} | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(json); | ||
}; | ||
try { | ||
const json = JSON.parse(responseText); | ||
respond(null, json); | ||
resolve(isJSON ? json : responseText); | ||
} catch (err) { | ||
respond(err); | ||
reject(err); | ||
} | ||
@@ -151,3 +139,9 @@ }); | ||
}, | ||
); | ||
) | ||
.catch((err) => { | ||
if (err.statusCode === 404) { | ||
return null; | ||
} | ||
throw err; | ||
}); | ||
@@ -154,0 +148,0 @@ const getByIds = ( |
{ | ||
"name": "@laboratoria/hubspot", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Unofficial Hubspot Node.js client", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
6987
173