Skip to content

Commit

Permalink
[kfetch] Add support for interceptors (#22128)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Aug 31, 2018
1 parent 8c3f4af commit 1daa265
Show file tree
Hide file tree
Showing 6 changed files with 525 additions and 123 deletions.
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

0 comments on commit 1daa265

Please sign in to comment.