|
8 | 8 | import { schema } from '@kbn/config-schema'; |
9 | 9 | import { IRouter } from '@kbn/core/server'; |
10 | 10 |
|
11 | | -import { ILicenseState } from '../lib'; |
12 | | -import { verifyAccessAndContext, rewriteRule } from './lib'; |
| 11 | +import { ILicenseState, RuleTypeDisabledError } from '../lib'; |
| 12 | +import { verifyAccessAndContext, rewriteRule, handleDisabledApiKeysError } from './lib'; |
13 | 13 | import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types'; |
14 | 14 |
|
15 | 15 | const ruleActionSchema = schema.object({ |
@@ -58,20 +58,29 @@ const buildBulkEditRulesRoute = ({ licenseState, path, router }: BuildBulkEditRu |
58 | 58 | body: bodySchema, |
59 | 59 | }, |
60 | 60 | }, |
61 | | - router.handleLegacyErrors( |
62 | | - verifyAccessAndContext(licenseState, async function (context, req, res) { |
63 | | - const rulesClient = (await context.alerting).getRulesClient(); |
64 | | - const { filter, operations, ids } = req.body; |
| 61 | + handleDisabledApiKeysError( |
| 62 | + router.handleLegacyErrors( |
| 63 | + verifyAccessAndContext(licenseState, async function (context, req, res) { |
| 64 | + const rulesClient = (await context.alerting).getRulesClient(); |
| 65 | + const { filter, operations, ids } = req.body; |
65 | 66 |
|
66 | | - const bulkEditResults = await rulesClient.bulkEdit({ |
67 | | - filter, |
68 | | - ids: ids as string[], |
69 | | - operations, |
70 | | - }); |
71 | | - return res.ok({ |
72 | | - body: { ...bulkEditResults, rules: bulkEditResults.rules.map(rewriteRule) }, |
73 | | - }); |
74 | | - }) |
| 67 | + try { |
| 68 | + const bulkEditResults = await rulesClient.bulkEdit({ |
| 69 | + filter, |
| 70 | + ids: ids as string[], |
| 71 | + operations, |
| 72 | + }); |
| 73 | + return res.ok({ |
| 74 | + body: { ...bulkEditResults, rules: bulkEditResults.rules.map(rewriteRule) }, |
| 75 | + }); |
| 76 | + } catch (e) { |
| 77 | + if (e instanceof RuleTypeDisabledError) { |
| 78 | + return e.sendResponse(res); |
| 79 | + } |
| 80 | + throw e; |
| 81 | + } |
| 82 | + }) |
| 83 | + ) |
75 | 84 | ) |
76 | 85 | ); |
77 | 86 | }; |
|
0 commit comments