mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
Ensure we always catch errors on Rest calls
This commit is contained in:
@@ -20,7 +20,21 @@ function JobStatusGraphData(Rest, getBasePath, processErrors, $rootScope, $q) {
|
|||||||
function getData(period, jobType) {
|
function getData(period, jobType) {
|
||||||
var url = getBasePath('dashboard')+'graphs/jobs/?period='+period+'&job_type='+jobType;
|
var url = getBasePath('dashboard')+'graphs/jobs/?period='+period+'&job_type='+jobType;
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
return pluck('data', Rest.get());
|
var result = Rest.get()
|
||||||
|
.catch(function(response) {
|
||||||
|
var errorMessage = 'Failed to get: ' + response.url + ' GET returned: ' + response.status;
|
||||||
|
|
||||||
|
processErrors(null,
|
||||||
|
response.data,
|
||||||
|
response.status,
|
||||||
|
null, {
|
||||||
|
hdr: 'Error!',
|
||||||
|
msg: errorMessage
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
|
||||||
|
return pluck('data', result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -33,17 +47,6 @@ function JobStatusGraphData(Rest, getBasePath, processErrors, $rootScope, $q) {
|
|||||||
$broadcast('DataReceived:JobStatusGraph',
|
$broadcast('DataReceived:JobStatusGraph',
|
||||||
result);
|
result);
|
||||||
return result;
|
return result;
|
||||||
}).catch(function(response) {
|
|
||||||
var errorMessage = 'Failed to get: ' + response.url + ' GET returned: ' + response.status;
|
|
||||||
|
|
||||||
ProcessErrors(null,
|
|
||||||
response.data,
|
|
||||||
response.status,
|
|
||||||
null, {
|
|
||||||
hdr: 'Error!',
|
|
||||||
msg: errorMessage
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ describe('Job Status Graph Data Service', function() {
|
|||||||
$on: sinon.spy(),
|
$on: sinon.spy(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var processErrors = sinon.spy();
|
||||||
|
|
||||||
var getBasePath = function(path) {
|
var getBasePath = function(path) {
|
||||||
return '/' + path + '/';
|
return '/' + path + '/';
|
||||||
}
|
}
|
||||||
@@ -46,6 +48,7 @@ describe('Job Status Graph Data Service', function() {
|
|||||||
|
|
||||||
$provide.value("$cookieStore", { get: angular.noop });
|
$provide.value("$cookieStore", { get: angular.noop });
|
||||||
|
|
||||||
|
$provide.value('ProcessErrors', processErrors);
|
||||||
$provide.value('Rest', restStub);
|
$provide.value('Rest', restStub);
|
||||||
$provide.value('GetBasePath', getBasePath);
|
$provide.value('GetBasePath', getBasePath);
|
||||||
}));
|
}));
|
||||||
@@ -77,14 +80,20 @@ describe('Job Status Graph Data Service', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('processes errors through error handler', function() {
|
it('processes errors through error handler', function() {
|
||||||
var expected = { data: "error", status: "bad" };
|
var expected = { data: "blah", status: "bad" };
|
||||||
var actual = jobStatusGraphData.get();
|
var actual = jobStatusGraphData.get().catch(function() {
|
||||||
|
return processErrors;
|
||||||
|
});
|
||||||
|
|
||||||
restStub.fail(expected);
|
restStub.fail(expected);
|
||||||
|
|
||||||
flushPromises();
|
flushPromises();
|
||||||
|
|
||||||
return expect(actual).to.be.rejectedWith(expected);
|
return actual.catch(function() {
|
||||||
|
expect(processErrors).to
|
||||||
|
.have.been.calledWith(null, expected.data, expected.status);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('broadcasts event when data is received', function() {
|
it('broadcasts event when data is received', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user