Return an error for a canceled request.

Allow the datasource to decide how to handle a
canceled request.
This commit is contained in:
stuart nelson
2016-06-09 12:13:17 +02:00
parent bc7c2cd3f5
commit efdb990e56
2 changed files with 10 additions and 12 deletions

View File

@@ -120,17 +120,11 @@ function (angular, _, coreModule, config) {
return $http(options).then(null, function(err) { return $http(options).then(null, function(err) {
if (err.status === HTTP_REQUEST_ABORTED) { if (err.status === HTTP_REQUEST_ABORTED) {
// Need to return the right data structure so it has no effect on // TODO: Hitting refresh before the original request returns cancels
// iterating over returned data in datasource.ts#115 // the "loading" animation on the panes, but it should continue to be
// TODO: Hitting another refresh cancels the "loading" animation on // visible.
// panes. Figure out how to keep it going. err.statusText = "request aborted";
return { return err;
data: {
data: {
result: []
}
}
};
} }
// handle unauthorized for backend requests // handle unauthorized for backend requests

View File

@@ -58,6 +58,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
return escapedValues.join('|'); return escapedValues.join('|');
}; };
var HTTP_REQUEST_ABORTED = -1;
// Called once per panel (graph) // Called once per panel (graph)
this.query = function(options) { this.query = function(options) {
var self = this; var self = this;
@@ -107,6 +108,9 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
var result = []; var result = [];
_.each(allResponse, function(response, index) { _.each(allResponse, function(response, index) {
if (response.status === HTTP_REQUEST_ABORTED) {
return;
}
if (response.status === 'error') { if (response.status === 'error') {
self.lastErrors.query = response.error; self.lastErrors.query = response.error;
throw response.error; throw response.error;