Skip to content

Commit

Permalink
Convert default to named exports - errors (elastic#10986)
Browse files Browse the repository at this point in the history
* Convert default to named exports - errors

* Make all error classes use class syntax and extends

add tests

* Extending Error apparently doesn't work

* Merge PR elastic#11004 to try to fix test failures
  • Loading branch information
stacey-gammon committed Apr 4, 2017
1 parent ee2219d commit 57a70bb
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 214 deletions.
70 changes: 70 additions & 0 deletions src/ui/public/__tests__/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import expect from 'expect.js';
import {
SearchTimeout,
RequestFailure,
FetchFailure,
ShardFailure,
VersionConflict,
MappingConflict,
RestrictedMapping,
CacheWriteFailure,
FieldNotFoundInCache,
DuplicateField,
SavedObjectNotFound,
IndexPatternMissingIndices,
NoDefinedIndexPatterns,
NoDefaultIndexPattern,
PersistedStateError,
VislibError,
ContainerTooSmall,
InvalidWiggleSelection,
PieContainsAllZeros,
InvalidLogScaleValues,
StackedBarChartConfig,
NotEnoughData,
NoResults,
KbnError
} from 'ui/errors';

describe('ui/errors', () => {
const errors = [
new SearchTimeout(),
new RequestFailure('an error', { }),
new FetchFailure({ }),
new ShardFailure({ '_shards' : 5 }),
new VersionConflict({ }),
new MappingConflict({ }),
new RestrictedMapping('field', 'indexPattern'),
new CacheWriteFailure(),
new FieldNotFoundInCache('aname'),
new DuplicateField('dupfield'),
new SavedObjectNotFound('dashboard', '123'),
new IndexPatternMissingIndices(),
new NoDefinedIndexPatterns(),
new NoDefaultIndexPattern(),
new PersistedStateError(),
new VislibError('err'),
new ContainerTooSmall(),
new InvalidWiggleSelection(),
new PieContainsAllZeros(),
new InvalidLogScaleValues(),
new StackedBarChartConfig('err'),
new NotEnoughData('nodata'),
new NoResults()
];

errors.forEach(error => {
const className = error.constructor.name;
it(`${className} has a message`, () => {
expect(error.message).to.not.be.empty();
});

it(`${className} has a stack trace`, () => {
expect(error.stack).to.not.be.empty();
});

it (`${className} is an instance of KbnError`, () => {
expect(error instanceof KbnError).to.be(true);
});
});
});
4 changes: 1 addition & 3 deletions src/ui/public/courier/_redirect_when_missing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import errors from 'ui/errors';
import { SavedObjectNotFound } from 'ui/errors';

export default function RedirectWhenMissingFn($location, kbnUrl, Notifier, Promise) {
const SavedObjectNotFound = errors.SavedObjectNotFound;

const notify = new Notifier();

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/courier/data_source/_doc_send_to_es.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import _ from 'lodash';

import errors from 'ui/errors';
import { VersionConflict, RequestFailure } from 'ui/errors';
import RequestQueueProvider from 'ui/courier/_request_queue';
import FetchProvider from 'ui/courier/fetch/fetch';

Expand Down Expand Up @@ -36,7 +36,7 @@ export default function (Promise, Private, es, esAdmin, kbnIndex) {
const client = [].concat(params.index).includes(kbnIndex) ? esAdmin : es;
return client[method](params)
.then(function (resp) {
if (resp.status === 409) throw new errors.VersionConflict(resp);
if (resp.status === 409) throw new VersionConflict(resp);

doc._storeVersion(resp._version);
doc.id(resp._id);
Expand Down Expand Up @@ -85,7 +85,7 @@ export default function (Promise, Private, es, esAdmin, kbnIndex) {
})
.catch(function (err) {
// cast the error
throw new errors.RequestFailure(err);
throw new RequestFailure(err);
});
};
}
4 changes: 2 additions & 2 deletions src/ui/public/courier/saved_object/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import angular from 'angular';
import _ from 'lodash';

import errors from 'ui/errors';
import { SavedObjectNotFound } from 'ui/errors';
import uuid from 'node-uuid';
import MappingSetupProvider from 'ui/utils/mapping_setup';

Expand Down Expand Up @@ -211,7 +211,7 @@ export default function SavedObjectFactory(esAdmin, kbnIndex, Promise, Private,
this.applyESResp = (resp) => {
this._source = _.cloneDeep(resp._source);

if (resp.found != null && !resp.found) throw new errors.SavedObjectNotFound(esType, this.id);
if (resp.found != null && !resp.found) throw new SavedObjectNotFound(esType, this.id);

const meta = resp._source.kibanaSavedObjectMeta || {};
delete resp._source.kibanaSavedObjectMeta;
Expand Down

0 comments on commit 57a70bb

Please sign in to comment.