Skip to content

Commit

Permalink
Do not throw any error when fetchServices or fetchServiceOperations f…
Browse files Browse the repository at this point in the history
…ails

Signed-off-by: Yuri Roncella <[email protected]>
  • Loading branch information
Yuri Roncella committed Feb 12, 2019
1 parent 5d0e712 commit df52507
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/jaeger-ui/src/api/jaeger.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ const JaegerAPI = {
return getJSON(`${this.apiRoot}traces`, { query });
},
fetchServices() {
return getJSON(`${this.apiRoot}services`);
return getJSON(`${this.apiRoot}services`).catch(() => []);
},
fetchServiceOperations(serviceName) {
return getJSON(`${this.apiRoot}services/${encodeURIComponent(serviceName)}/operations`);
return getJSON(`${this.apiRoot}services/${encodeURIComponent(serviceName)}/operations`).catch(() => []);
},
fetchDependencies(endTs = new Date().getTime(), lookback = DEFAULT_DEPENDENCY_LOOKBACK) {
return getJSON(`${this.apiRoot}dependencies`, { query: { endTs, lookback } });
Expand Down
38 changes: 38 additions & 0 deletions packages/jaeger-ui/src/api/jaeger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,44 @@ it('fetchTrace() throws an error on a >= 400 status code', done => {
});
});

it('fetchServices() returns [] on a >= 400 status code', done => {
const status = 400;
const statusText = 'some-status';
const msg = 'some-message';
const errorData = { errors: [{ msg, code: status }] };

fetchMock.mockReturnValue(
Promise.resolve({
status,
statusText,
text: () => Promise.resolve(JSON.stringify(errorData)),
})
);
JaegerAPI.fetchServices().then(services => {
expect(services).toEqual([]);
done();
});
});

it('fetchOperations() returns [] on a >= 400 status code', done => {
const status = 400;
const statusText = 'some-status';
const msg = 'some-message';
const errorData = { errors: [{ msg, code: status }] };

fetchMock.mockReturnValue(
Promise.resolve({
status,
statusText,
text: () => Promise.resolve(JSON.stringify(errorData)),
})
);
JaegerAPI.fetchServiceOperations().then(operations => {
expect(operations).toEqual([]);
done();
});
});

it('fetchTrace() throws an useful error derived from a text payload', done => {
const status = 400;
const statusText = 'some-status';
Expand Down

0 comments on commit df52507

Please sign in to comment.