mirror of
https://github.com/ansible/awx.git
synced 2026-01-22 15:08:03 -03:30
Ensure we always catch errors on Rest calls
This commit is contained in:
parent
64484c4054
commit
50d9c11419
@ -20,7 +20,21 @@ function JobStatusGraphData(Rest, getBasePath, processErrors, $rootScope, $q) {
|
||||
function getData(period, jobType) {
|
||||
var url = getBasePath('dashboard')+'graphs/jobs/?period='+period+'&job_type='+jobType;
|
||||
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 {
|
||||
@ -33,17 +47,6 @@ function JobStatusGraphData(Rest, getBasePath, processErrors, $rootScope, $q) {
|
||||
$broadcast('DataReceived:JobStatusGraph',
|
||||
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(),
|
||||
};
|
||||
|
||||
var processErrors = sinon.spy();
|
||||
|
||||
var getBasePath = function(path) {
|
||||
return '/' + path + '/';
|
||||
}
|
||||
@ -46,6 +48,7 @@ describe('Job Status Graph Data Service', function() {
|
||||
|
||||
$provide.value("$cookieStore", { get: angular.noop });
|
||||
|
||||
$provide.value('ProcessErrors', processErrors);
|
||||
$provide.value('Rest', restStub);
|
||||
$provide.value('GetBasePath', getBasePath);
|
||||
}));
|
||||
@ -77,14 +80,20 @@ describe('Job Status Graph Data Service', function() {
|
||||
});
|
||||
|
||||
it('processes errors through error handler', function() {
|
||||
var expected = { data: "error", status: "bad" };
|
||||
var actual = jobStatusGraphData.get();
|
||||
var expected = { data: "blah", status: "bad" };
|
||||
var actual = jobStatusGraphData.get().catch(function() {
|
||||
return processErrors;
|
||||
});
|
||||
|
||||
restStub.fail(expected);
|
||||
|
||||
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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user