Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] [kfetch] Add support for interceptors (#22128) #22584

Merged
merged 1 commit into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import fetchMock from 'fetch-mock';
import { kfetch } from 'ui/kfetch';
import { isAutoCreateIndexError } from './error_auto_create_index';

describe('isAutoCreateIndexError correctly handles FetchError thrown by kfetch', () => {
describe('isAutoCreateIndexError correctly handles KFetchError thrown by kfetch', () => {
describe('404', () => {
beforeEach(() => {
fetchMock.post({
Expand All @@ -43,15 +43,12 @@ describe('isAutoCreateIndexError correctly handles FetchError thrown by kfetch',
afterEach(() => fetchMock.restore());

test('should return false', async () => {
let gotError = false;
expect.assertions(1);
try {
await kfetch({ method: 'POST', pathname: 'my/path' });
} catch (fetchError) {
gotError = true;
expect(isAutoCreateIndexError(fetchError)).toBe(false);
} catch (kfetchError) {
expect(isAutoCreateIndexError(kfetchError)).toBe(false);
}

expect(gotError).toBe(true);
});
});

Expand All @@ -67,15 +64,12 @@ describe('isAutoCreateIndexError correctly handles FetchError thrown by kfetch',
afterEach(() => fetchMock.restore());

test('should return false', async () => {
let gotError = false;
expect.assertions(1);
try {
await kfetch({ method: 'POST', pathname: 'my/path' });
} catch (fetchError) {
gotError = true;
expect(isAutoCreateIndexError(fetchError)).toBe(false);
} catch (kfetchError) {
expect(isAutoCreateIndexError(kfetchError)).toBe(false);
}

expect(gotError).toBe(true);
});
});

Expand All @@ -85,7 +79,7 @@ describe('isAutoCreateIndexError correctly handles FetchError thrown by kfetch',
matcher: '*',
response: {
body: {
code: 'ES_AUTO_CREATE_INDEX_ERROR'
code: 'ES_AUTO_CREATE_INDEX_ERROR',
},
status: 503,
},
Expand All @@ -94,16 +88,12 @@ describe('isAutoCreateIndexError correctly handles FetchError thrown by kfetch',
afterEach(() => fetchMock.restore());

test('should return true', async () => {
let gotError = false;
expect.assertions(1);
try {
await kfetch({ method: 'POST', pathname: 'my/path' });
} catch (fetchError) {
gotError = true;
expect(isAutoCreateIndexError(fetchError)).toBe(true);
} catch (kfetchError) {
expect(isAutoCreateIndexError(kfetchError)).toBe(true);
}

expect(gotError).toBe(true);
});
});
});

2 changes: 1 addition & 1 deletion src/ui/public/kfetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export { kfetch } from './kfetch';
export { kfetch, addInterceptor } from './kfetch';
export { kfetchAbortable } from './kfetch_abortable';
Loading