Workround for status errors thrown by d3-xml

Because the done callback is expecting something that has a `status` property,
(like an XHR would), we need to extract the status out of the error message.
d3-xml includes status in the error message, but we can't access the response itself.
This commit is contained in:
Bryan Housel
2019-04-26 22:23:08 -04:00
parent b99be67169
commit b48a7d1e1b
+12 -3
View File
@@ -440,7 +440,8 @@ export default {
// 400 Bad Request, 401 Unauthorized, 403 Forbidden
// Logout and retry the request..
if (isAuthenticated && err && (err.status === 400 || err.status === 401 || err.status === 403)) {
if (isAuthenticated && err && err.status &&
(err.status === 400 || err.status === 401 || err.status === 403)) {
that.logout();
that.loadFromAPI(path, callback, options);
@@ -448,7 +449,7 @@ export default {
} else {
// 509 Bandwidth Limit Exceeded, 429 Too Many Requests
// Set the rateLimitError flag and trigger a warning..
if (!isAuthenticated && !_rateLimitError && err &&
if (!isAuthenticated && !_rateLimitError && err && err.status &&
(err.status === 509 || err.status === 429)) {
_rateLimitError = err;
dispatch.call('change');
@@ -475,7 +476,15 @@ export default {
})
.catch(function(err) {
if (err.name === 'AbortError') return;
done(err.message);
// d3-fetch includes status in the error message,
// but we can't access the response itself
// https://github.com/d3/d3-fetch/issues/27
var match = err.message.match(/^\d{3}/);
if (match) {
done({ status: +match[0], statusText: err.message });
} else {
done(err.message);
}
});
return controller;
}