Skip to content

Commit 28e288e

Browse files
committed
Handle errors better
1 parent 863b326 commit 28e288e

1 file changed

Lines changed: 41 additions & 39 deletions

File tree

x-pack/plugins/monitoring/server/plugin.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
import Boom from 'boom';
67
import { combineLatest } from 'rxjs';
78
import { first } from 'rxjs/operators';
89
import { i18n } from '@kbn/i18n';
@@ -335,49 +336,50 @@ export class Plugin {
335336
log: this.log,
336337
route: (options: any) => {
337338
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,
358357
},
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+
}),
374371
},
375372
},
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 });
379379
}
380-
);
380+
return res.ok({ body: result });
381+
};
382+
381383
const validate: any = get(options, 'config.validate', false);
382384
if (validate && validate.payload) {
383385
validate.body = validate.payload;

0 commit comments

Comments
 (0)