diff --git a/x-pack/plugins/alerting/public/alert_api.test.ts b/x-pack/plugins/alerting/public/alert_api.test.ts index 152097d084eb86..023ea255e1c42d 100644 --- a/x-pack/plugins/alerting/public/alert_api.test.ts +++ b/x-pack/plugins/alerting/public/alert_api.test.ts @@ -78,25 +78,6 @@ describe('loadAlertType', () => { expect(await loadAlertType({ http, id: 'test-another' })).toEqual(alertType); }); - - test('should throw if required alertType is missing', async () => { - http.get.mockResolvedValueOnce([ - { - id: 'test-another', - name: 'Test Another', - actionVariables: [], - actionGroups: [{ id: 'default', name: 'Default' }], - defaultActionGroupId: 'default', - minimumLicenseRequired: 'basic', - recoveryActionGroup: RecoveredActionGroup, - producer: 'alerts', - }, - ]); - - expect(loadAlertType({ http, id: 'test' })).rejects.toMatchInlineSnapshot( - `[Error: Alert type "test" is not registered.]` - ); - }); }); describe('loadAlert', () => { diff --git a/x-pack/plugins/alerting/public/alert_api.ts b/x-pack/plugins/alerting/public/alert_api.ts index d1213c80b95be1..f3faa65a4b384b 100644 --- a/x-pack/plugins/alerting/public/alert_api.ts +++ b/x-pack/plugins/alerting/public/alert_api.ts @@ -6,7 +6,6 @@ */ import { HttpSetup } from 'kibana/public'; -import { i18n } from '@kbn/i18n'; import { LEGACY_BASE_ALERT_API_PATH } from '../common'; import type { Alert, AlertType } from '../common'; @@ -20,21 +19,11 @@ export async function loadAlertType({ }: { http: HttpSetup; id: AlertType['id']; -}): Promise { - const maybeAlertType = ((await http.get( +}): Promise { + const alertTypes = (await http.get( `${LEGACY_BASE_ALERT_API_PATH}/list_alert_types` - )) as AlertType[]).find((type) => type.id === id); - if (!maybeAlertType) { - throw new Error( - i18n.translate('xpack.alerting.loadAlertType.missingAlertTypeError', { - defaultMessage: 'Alert type "{id}" is not registered.', - values: { - id, - }, - }) - ); - } - return maybeAlertType; + )) as AlertType[]; + return alertTypes.find((type) => type.id === id); } export async function loadAlert({ diff --git a/x-pack/plugins/alerting/public/plugin.ts b/x-pack/plugins/alerting/public/plugin.ts index 5ca3c0af268013..025467d92a6ace 100644 --- a/x-pack/plugins/alerting/public/plugin.ts +++ b/x-pack/plugins/alerting/public/plugin.ts @@ -30,14 +30,19 @@ export class AlertingPublicPlugin implements Plugin - this.alertNavigationRegistry!.register( - consumer, - await loadAlertType({ http: core.http, id: alertType }), - handler - ); + ) => { + const alertType = await loadAlertType({ http: core.http, id: alertTypeId }); + if (!alertType) { + // eslint-disable-next-line no-console + console.log( + `Unable to register navigation for alert type "${alertTypeId}" because it is not registered on the server side.` + ); + return; + } + this.alertNavigationRegistry!.register(consumer, alertType, handler); + }; const registerDefaultNavigation = async (consumer: string, handler: AlertNavigationHandler) => this.alertNavigationRegistry!.registerDefault(consumer, handler); @@ -54,6 +59,14 @@ export class AlertingPublicPlugin implements Plugin