forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid reliance on Boom and instead relly on SO helpers
- Loading branch information
Showing
6 changed files
with
86 additions
and
17 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/alerting/server/lib/is_alert_not_found_error.test.ts
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,31 @@ | ||
/* | ||
* 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 { isAlertSavedObjectNotFoundError } from './is_alert_not_found_error'; | ||
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; | ||
import uuid from 'uuid'; | ||
|
||
describe('isAlertSavedObjectNotFoundError', () => { | ||
test('identifies SavedObjects Not Found errors', () => { | ||
const id = uuid.v4(); | ||
// ensure the error created by SO parses as a string with the format we expect | ||
expect( | ||
`${SavedObjectsErrorHelpers.createGenericNotFoundError('alert', id)}`.includes(`alert/${id}`) | ||
).toBe(true); | ||
|
||
const errorBySavedObjectsHelper = SavedObjectsErrorHelpers.createGenericNotFoundError( | ||
'alert', | ||
id | ||
); | ||
|
||
expect(isAlertSavedObjectNotFoundError(errorBySavedObjectsHelper, id)).toBe(true); | ||
}); | ||
|
||
test('identifies generic errors', () => { | ||
const id = uuid.v4(); | ||
expect(isAlertSavedObjectNotFoundError(new Error(`not found`), id)).toBe(false); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/alerting/server/lib/is_alert_not_found_error.ts
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,11 @@ | ||
/* | ||
* 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 { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; | ||
|
||
export function isAlertSavedObjectNotFoundError(err: Error, alertId: string) { | ||
return SavedObjectsErrorHelpers.isNotFoundError(err) && `${err}`.includes(alertId); | ||
} |
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
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/task_manager/server/lib/is_task_not_found_error.test.ts
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,31 @@ | ||
/* | ||
* 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 { isTaskSavedObjectNotFoundError } from './is_task_not_found_error'; | ||
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; | ||
import uuid from 'uuid'; | ||
|
||
describe('isTaskSavedObjectNotFoundError', () => { | ||
test('identifies SavedObjects Not Found errors', () => { | ||
const id = uuid.v4(); | ||
// ensure the error created by SO parses as a string with the format we expect | ||
expect( | ||
`${SavedObjectsErrorHelpers.createGenericNotFoundError('task', id)}`.includes(`task/${id}`) | ||
).toBe(true); | ||
|
||
const errorBySavedObjectsHelper = SavedObjectsErrorHelpers.createGenericNotFoundError( | ||
'task', | ||
id | ||
); | ||
|
||
expect(isTaskSavedObjectNotFoundError(errorBySavedObjectsHelper, id)).toBe(true); | ||
}); | ||
|
||
test('identifies generic errors', () => { | ||
const id = uuid.v4(); | ||
expect(isTaskSavedObjectNotFoundError(new Error(`not found`), id)).toBe(false); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/task_manager/server/lib/is_task_not_found_error.ts
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,11 @@ | ||
/* | ||
* 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 { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; | ||
|
||
export function isTaskSavedObjectNotFoundError(err: Error, taskId: string) { | ||
return SavedObjectsErrorHelpers.isNotFoundError(err) && `${err}`.includes(taskId); | ||
} |
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