|
3 | 3 | * or more contributor license agreements. Licensed under the Elastic License; |
4 | 4 | * you may not use this file except in compliance with the Elastic License. |
5 | 5 | */ |
| 6 | +import Boom from 'boom'; |
6 | 7 | import { combineLatest } from 'rxjs'; |
7 | 8 | import { first } from 'rxjs/operators'; |
8 | 9 | import { i18n } from '@kbn/i18n'; |
@@ -335,49 +336,50 @@ export class Plugin { |
335 | 336 | log: this.log, |
336 | 337 | route: (options: any) => { |
337 | 338 | const method = options.method; |
338 | | - const handler = router.handleLegacyErrors( |
339 | | - async ( |
340 | | - context: RequestHandlerContext, |
341 | | - req: KibanaRequest<any, any, any, any>, |
342 | | - res: KibanaResponseFactory |
343 | | - ) => { |
344 | | - const legacyRequest = { |
345 | | - ...req, |
346 | | - logger: this.log, |
347 | | - getLogger: this.getLogger, |
348 | | - payload: req.body, |
349 | | - getKibanaStatsCollector: () => this.legacyShimDependencies.kibanaStatsCollector, |
350 | | - getUiSettingsService: () => context.core.uiSettings.client, |
351 | | - getAlertsClient: () => plugins.alerting.getAlertsClientWithRequest(req), |
352 | | - server: { |
353 | | - config: legacyConfigWrapper, |
354 | | - newPlatform: { |
355 | | - setup: { |
356 | | - plugins, |
357 | | - }, |
| 339 | + const handler = async ( |
| 340 | + context: RequestHandlerContext, |
| 341 | + req: KibanaRequest<any, any, any, any>, |
| 342 | + res: KibanaResponseFactory |
| 343 | + ) => { |
| 344 | + const legacyRequest = { |
| 345 | + ...req, |
| 346 | + logger: this.log, |
| 347 | + getLogger: this.getLogger, |
| 348 | + payload: req.body, |
| 349 | + getKibanaStatsCollector: () => this.legacyShimDependencies.kibanaStatsCollector, |
| 350 | + getUiSettingsService: () => context.core.uiSettings.client, |
| 351 | + getAlertsClient: () => plugins.alerting.getAlertsClientWithRequest(req), |
| 352 | + server: { |
| 353 | + config: legacyConfigWrapper, |
| 354 | + newPlatform: { |
| 355 | + setup: { |
| 356 | + plugins, |
358 | 357 | }, |
359 | | - plugins: { |
360 | | - monitoring: { |
361 | | - info: licenseService, |
362 | | - }, |
363 | | - elasticsearch: { |
364 | | - getCluster: (name: string) => ({ |
365 | | - callWithRequest: async (_req: any, endpoint: string, params: any) => { |
366 | | - const client = |
367 | | - name === 'monitoring' |
368 | | - ? cluster |
369 | | - : this.legacyShimDependencies.esDataClient; |
370 | | - return client.asScoped(req).callAsCurrentUser(endpoint, params); |
371 | | - }, |
372 | | - }), |
373 | | - }, |
| 358 | + }, |
| 359 | + plugins: { |
| 360 | + monitoring: { |
| 361 | + info: licenseService, |
| 362 | + }, |
| 363 | + elasticsearch: { |
| 364 | + getCluster: (name: string) => ({ |
| 365 | + callWithRequest: async (_req: any, endpoint: string, params: any) => { |
| 366 | + const client = |
| 367 | + name === 'monitoring' ? cluster : this.legacyShimDependencies.esDataClient; |
| 368 | + return client.asScoped(req).callAsCurrentUser(endpoint, params); |
| 369 | + }, |
| 370 | + }), |
374 | 371 | }, |
375 | 372 | }, |
376 | | - }; |
377 | | - const result = await options.handler(legacyRequest); |
378 | | - return res.ok({ body: result }); |
| 373 | + }, |
| 374 | + }; |
| 375 | + |
| 376 | + const result = await options.handler(legacyRequest); |
| 377 | + if (Boom.isBoom(result)) { |
| 378 | + return res.customError({ statusCode: result.output.statusCode, body: result }); |
379 | 379 | } |
380 | | - ); |
| 380 | + return res.ok({ body: result }); |
| 381 | + }; |
| 382 | + |
381 | 383 | const validate: any = get(options, 'config.validate', false); |
382 | 384 | if (validate && validate.payload) { |
383 | 385 | validate.body = validate.payload; |
|
0 commit comments