Comparing version 0.2.3 to 0.2.4
@@ -40,3 +40,20 @@ "use strict"; | ||
if (req.status >= 200 && req.status < 400) { | ||
resolve(JSON.parse(req.responseText)); | ||
// The 204 response MUST NOT include a message-body ... | ||
if (req.status === 204) { | ||
resolve(null); | ||
} | ||
try { | ||
resolve(JSON.parse(req.responseText)); | ||
} catch (e) { | ||
reject({ | ||
code: "INVALID_RESPONSE", | ||
title: "Response isn't valid JSON", | ||
description: "The response couldn't be parsed into an Javascript object. Check that the endpoint is valid?", | ||
details: { | ||
endpoint: endpoint, | ||
responseText: req.responseText | ||
} | ||
}); | ||
} | ||
} else { | ||
@@ -43,0 +60,0 @@ try { |
@@ -162,23 +162,25 @@ 'use strict'; | ||
// notify all subscriptions that have mapping (via entityToResource) to any of the entities | ||
var entities = data.items ? data.items : data.url ? [data] : []; | ||
//console.log('notify all subscriptions that have mapping to any of the enitities',entities) | ||
if (data) { | ||
var entities = data.items ? data.items : data.url ? [data] : []; | ||
//console.log('notify all subscriptions that have mapping to any of the enitities',entities) | ||
entities.forEach(function (entity) { | ||
var resources = entityToResource[entity.url]; | ||
//console.log('notify for entity',entity.url,resources) | ||
if (resources) { | ||
resources.forEach(function (r) { | ||
var response = resourceCache[r]; | ||
subscriptions = resourceToSubscription[r]; | ||
if (subscriptions) { | ||
subscriptions.forEach(function (s) { | ||
if (!called[s.id]) { | ||
s.callback(err, response, s.unsubscribeFn); | ||
called[s.id] = true; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
entities.forEach(function (entity) { | ||
var resources = entityToResource[entity.url]; | ||
//console.log('notify for entity',entity.url,resources) | ||
if (resources) { | ||
resources.forEach(function (r) { | ||
var response = resourceCache[r]; | ||
subscriptions = resourceToSubscription[r]; | ||
if (subscriptions) { | ||
subscriptions.forEach(function (s) { | ||
if (!called[s.id]) { | ||
s.callback(err, response, s.unsubscribeFn); | ||
called[s.id] = true; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}, | ||
@@ -238,3 +240,2 @@ | ||
// (token, url, endpoint, {method, body} = {method: 'GET', body: null}) | ||
create: function refresh(resource, content) { | ||
@@ -250,7 +251,2 @@ var _this2 = this; | ||
}); | ||
promise.catch(function (err) { | ||
return setTimeout(function () { | ||
return _this2._internal.publish(resource, null, err); | ||
}, 0); | ||
}); | ||
return promise; | ||
@@ -269,7 +265,2 @@ }, | ||
}); | ||
promise.catch(function (err) { | ||
return setTimeout(function () { | ||
return _this3._internal.publish(resource, null, err); | ||
}, 0); | ||
}); | ||
return promise; | ||
@@ -281,3 +272,3 @@ }, | ||
this.debug && console.log('remove', resource, content); | ||
this.debug && console.log('remove', resource); | ||
var promise = (0, _fetch2.fetch)(token, resource, endpoint, { method: 'DELETE', body: null }); | ||
@@ -292,8 +283,2 @@ | ||
promise.catch(function (err) { | ||
return setTimeout(function () { | ||
return _this4._internal.publish(resource, null, err); | ||
}, 0); | ||
}); | ||
return promise; | ||
@@ -300,0 +285,0 @@ }, |
{ | ||
"name": "six-sdk", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "SIX Javascript SDK", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
43856
1102