Skip to content

Commit 0e1f2eb

Browse files
committed
Fix http interceptor bug preventing 4xx/5xx responses from being caught
1 parent e57009c commit 0e1f2eb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,24 @@ describe('HttpLogic', () => {
7474
describe('errorConnectingInterceptor', () => {
7575
it('handles errors connecting to Enterprise Search', async () => {
7676
const { responseError } = mockHttp.intercept.mock.calls[0][0] as any;
77-
await responseError({ response: { url: '/api/app_search/engines', status: 502 } });
77+
const httpResponse = { response: { url: '/api/app_search/engines', status: 502 } };
78+
await expect(responseError(httpResponse)).rejects.toEqual(httpResponse);
7879

7980
expect(HttpLogic.actions.setErrorConnecting).toHaveBeenCalled();
8081
});
8182

8283
it('does not handle non-502 Enterprise Search errors', async () => {
8384
const { responseError } = mockHttp.intercept.mock.calls[0][0] as any;
84-
await responseError({ response: { url: '/api/workplace_search/overview', status: 404 } });
85+
const httpResponse = { response: { url: '/api/workplace_search/overview', status: 404 } };
86+
await expect(responseError(httpResponse)).rejects.toEqual(httpResponse);
8587

8688
expect(HttpLogic.actions.setErrorConnecting).not.toHaveBeenCalled();
8789
});
8890

8991
it('does not handle errors for unrelated calls', async () => {
9092
const { responseError } = mockHttp.intercept.mock.calls[0][0] as any;
91-
await responseError({ response: { url: '/api/some_other_plugin/', status: 502 } });
93+
const httpResponse = { response: { url: '/api/some_other_plugin/', status: 502 } };
94+
await expect(responseError(httpResponse)).rejects.toEqual(httpResponse);
9295

9396
expect(HttpLogic.actions.setErrorConnecting).not.toHaveBeenCalled();
9497
});

x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export const HttpLogic = kea<MakeLogicType<IHttpValues, IHttpActions>>({
6868
if (isApiResponse && hasErrorConnecting) {
6969
actions.setErrorConnecting(true);
7070
}
71-
return httpResponse;
71+
72+
// Re-throw error so that downstream catches work as expected
73+
return Promise.reject(httpResponse);
7274
},
7375
});
7476
httpInterceptors.push(errorConnectingInterceptor);

0 commit comments

Comments
 (0)