Skip to content

Commit

Permalink
[savedObjects/mappingFallback] check for body.error.type
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Aug 18, 2017
1 parent e2ef21e commit 9facf4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import expect from 'expect.js';
import sinon from 'sinon';

import { SavedObjectsClient } from '../saved_objects_client';
import { decorateEsError } from '../lib';
const { BadRequest } = elasticsearch.errors;

describe('SavedObjectsClient', () => {
Expand All @@ -23,11 +24,11 @@ describe('SavedObjectsClient', () => {

describe('#create', () => {
it('falls back to single-type mapping', async () => {
const error = new BadRequest('[illegal_argument_exception] Rejecting mapping update to [.kibana-v6]', {
const error = decorateEsError(new BadRequest('[illegal_argument_exception] Rejecting mapping update to [.kibana-v6]', {
body: {
error: illegalArgumentException
}
});
}));

callAdminCluster
.onFirstCall().throws(error)
Expand All @@ -49,11 +50,11 @@ describe('SavedObjectsClient', () => {

it('prepends id for single-type', async () => {
const id = 'foo';
const error = new BadRequest('[illegal_argument_exception] Rejecting mapping update to [.kibana-v6]', {
const error = decorateEsError(new BadRequest('[illegal_argument_exception] Rejecting mapping update to [.kibana-v6]', {
body: {
error: illegalArgumentException
}
});
}));

callAdminCluster
.onFirstCall().throws(error)
Expand Down Expand Up @@ -154,13 +155,13 @@ describe('SavedObjectsClient', () => {
const type = 'index-pattern';
const version = 2;
const attributes = { title: 'Testing' };
const error = new BadRequest('[document_missing_exception] [config][logstash-*]: document missing', {
const error = decorateEsError(new BadRequest('[document_missing_exception] [config][logstash-*]: document missing', {
body: {
error: {
type: 'document_missing_exception'
}
}
});
}));

beforeEach(() => {
callAdminCluster
Expand Down
10 changes: 8 additions & 2 deletions src/server/saved_objects/client/saved_objects_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,14 @@ export class SavedObjectsClient {
};

return this._withKibanaIndex(method, params).catch(err => {
if (get(fallbacks, method, []).includes(get(err, 'data.type'))) {
return this._withKibanaIndex(method, Object.assign({}, params, fallbackParams));
const fallbackWhen = get(fallbacks, method, []);
const type = get(err, 'body.error.type');

if (type && fallbackWhen.includes(type)) {
return this._withKibanaIndex(method, {
...params,
...fallbackParams
});
}

throw err;
Expand Down

0 comments on commit 9facf4d

Please sign in to comment.