-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ba28ac
commit fa3b8c0
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { GlobalSearchFindError } from './errors'; | ||
|
||
describe('GlobalSearchFindError', () => { | ||
describe('#invalidLicense', () => { | ||
it('create an error with the correct `type`', () => { | ||
const error = GlobalSearchFindError.invalidLicense('foobar'); | ||
expect(error.message).toBe('foobar'); | ||
expect(error.type).toBe('invalid-license'); | ||
}); | ||
|
||
it('can be identified via instanceof', () => { | ||
const error = GlobalSearchFindError.invalidLicense('foo'); | ||
expect(error instanceof GlobalSearchFindError).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// only one type for now, but already present for future-proof reasons | ||
export type GlobalSearchFindErrorType = 'invalid-license'; | ||
|
||
/** | ||
* Error thrown from the {@link GlobalSearchPluginStart.find | GlobalSearch find API}'s result observable | ||
* | ||
* @public | ||
*/ | ||
export class GlobalSearchFindError extends Error { | ||
public static invalidLicense(message: string) { | ||
return new GlobalSearchFindError('invalid-license', message); | ||
} | ||
|
||
private constructor(public readonly type: GlobalSearchFindErrorType, message: string) { | ||
super(message); | ||
|
||
// Set the prototype explicitly, see: | ||
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
Object.setPrototypeOf(this, GlobalSearchFindError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters