[7.x] [HTTP] Apply the same behaviour to all 500 errors (except from custom
responses) (#85541) (#91892)
* [HTTP] Apply the same behaviour to all 500 errors (except from `custom` responses) (#85541) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # x-pack/plugins/security/server/routes/authentication/saml.ts * Fix deprecated route * Mock before calling the method
This commit is contained in:
parent
890ddce74f
commit
6da1e935bd
|
@ -19,7 +19,6 @@ kibanaResponseFactory: {
|
|||
forbidden: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
notFound: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
conflict: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
internalError: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
customError: (options: CustomHttpResponseOptions<ResponseError>) => KibanaResponse<ResponseError>;
|
||||
redirected: (options: RedirectResponseOptions) => KibanaResponse<string | Record<string, any> | Buffer | Stream>;
|
||||
ok: (options?: HttpResponseOptions) => KibanaResponse<string | Record<string, any> | Buffer | Stream>;
|
||||
|
|
|
@ -283,7 +283,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [PluginOpaqueId](./kibana-plugin-core-server.pluginopaqueid.md) | |
|
||||
| [PublicUiSettingsParams](./kibana-plugin-core-server.publicuisettingsparams.md) | A sub-set of [UiSettingsParams](./kibana-plugin-core-server.uisettingsparams.md) exposed to the client-side. |
|
||||
| [RedirectResponseOptions](./kibana-plugin-core-server.redirectresponseoptions.md) | HTTP response parameters for redirection response |
|
||||
| [RequestHandler](./kibana-plugin-core-server.requesthandler.md) | A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) functions. |
|
||||
| [RequestHandler](./kibana-plugin-core-server.requesthandler.md) | A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) functions. If anything else is returned, or an error is thrown, the HTTP service will automatically log the error and respond <code>500 - Internal Server Error</code>. |
|
||||
| [RequestHandlerContextContainer](./kibana-plugin-core-server.requesthandlercontextcontainer.md) | An object that handles registration of http request context providers. |
|
||||
| [RequestHandlerContextProvider](./kibana-plugin-core-server.requesthandlercontextprovider.md) | Context provider for request handler. Extends request context object with provided functionality or data. |
|
||||
| [RequestHandlerWrapper](./kibana-plugin-core-server.requesthandlerwrapper.md) | Type-safe wrapper for [RequestHandler](./kibana-plugin-core-server.requesthandler.md) function. |
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
## RequestHandler type
|
||||
|
||||
A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) functions.
|
||||
A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) functions. If anything else is returned, or an error is thrown, the HTTP service will automatically log the error and respond `500 - Internal Server Error`<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
|
|
@ -705,12 +705,8 @@ describe('BasePathProxyServer', () => {
|
|||
options: { body: { output: 'stream' } },
|
||||
},
|
||||
(_, req, res) => {
|
||||
try {
|
||||
expect(req.body).toBeInstanceOf(Readable);
|
||||
return res.ok({ body: req.route.options.body });
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -740,15 +736,11 @@ describe('BasePathProxyServer', () => {
|
|||
},
|
||||
},
|
||||
(_, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -779,15 +771,11 @@ describe('BasePathProxyServer', () => {
|
|||
},
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -815,15 +803,11 @@ describe('BasePathProxyServer', () => {
|
|||
},
|
||||
},
|
||||
(_, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -851,15 +835,11 @@ describe('BasePathProxyServer', () => {
|
|||
},
|
||||
},
|
||||
(_, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
|
|
@ -151,7 +151,6 @@ const createResponseFactoryMock = (): jest.Mocked<KibanaResponseFactory> => ({
|
|||
forbidden: jest.fn(),
|
||||
notFound: jest.fn(),
|
||||
conflict: jest.fn(),
|
||||
internalError: jest.fn(),
|
||||
customError: jest.fn(),
|
||||
});
|
||||
|
||||
|
@ -162,7 +161,6 @@ const createLifecycleResponseFactoryMock = (): jest.Mocked<LifecycleResponseFact
|
|||
forbidden: jest.fn(),
|
||||
notFound: jest.fn(),
|
||||
conflict: jest.fn(),
|
||||
internalError: jest.fn(),
|
||||
customError: jest.fn(),
|
||||
});
|
||||
|
||||
|
|
|
@ -1016,13 +1016,9 @@ describe('body options', () => {
|
|||
options: { body: { parse: false } },
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
expect(req.body).toBeInstanceOf(Buffer);
|
||||
expect(req.body.toString()).toBe(JSON.stringify({ test: 1 }));
|
||||
return res.ok({ body: req.route.options.body });
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -1053,15 +1049,11 @@ describe('timeout options', () => {
|
|||
},
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -1091,15 +1083,11 @@ describe('timeout options', () => {
|
|||
},
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -1128,15 +1116,11 @@ describe('timeout options', () => {
|
|||
},
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -1165,15 +1149,11 @@ describe('timeout options', () => {
|
|||
},
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
return res.ok({
|
||||
body: {
|
||||
timeout: req.route.options.timeout,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
@ -1294,12 +1274,8 @@ test('should return a stream in the body', async () => {
|
|||
options: { body: { output: 'stream' } },
|
||||
},
|
||||
(context, req, res) => {
|
||||
try {
|
||||
expect(req.body).toBeInstanceOf(Readable);
|
||||
return res.ok({ body: req.route.options.body });
|
||||
} catch (err) {
|
||||
return res.internalError({ body: err.message });
|
||||
}
|
||||
}
|
||||
);
|
||||
registerRouter(router);
|
||||
|
|
|
@ -1672,7 +1672,11 @@ describe('Response factory', () => {
|
|||
|
||||
const result = await supertest(innerServer.listener).get('/').expect(500);
|
||||
|
||||
expect(result.body.message).toBe('reason');
|
||||
expect(result.body).toEqual({
|
||||
error: 'Internal Server Error',
|
||||
message: 'reason',
|
||||
statusCode: 500,
|
||||
});
|
||||
expect(loggingSystemMock.collect(logger).error).toHaveLength(0);
|
||||
});
|
||||
|
||||
|
|
|
@ -177,15 +177,6 @@ const errorResponseFactory = {
|
|||
conflict: (options: ErrorHttpResponseOptions = {}) =>
|
||||
new KibanaResponse(409, options.body || 'Conflict', options),
|
||||
|
||||
// Server error
|
||||
/**
|
||||
* The server encountered an unexpected condition that prevented it from fulfilling the request.
|
||||
* Status code: `500`.
|
||||
* @param options - {@link HttpResponseOptions} configures HTTP response headers, error message and other error details to pass to the client
|
||||
*/
|
||||
internalError: (options: ErrorHttpResponseOptions = {}) =>
|
||||
new KibanaResponse(500, options.body || 'Internal Error', options),
|
||||
|
||||
/**
|
||||
* Creates an error response with defined status code and payload.
|
||||
* @param options - {@link CustomHttpResponseOptions} configures HTTP response headers, error message and other error details to pass to the client
|
||||
|
|
|
@ -314,6 +314,8 @@ type RequestHandlerEnhanced<P, Q, B, Method extends RouteMethod> = WithoutHeadAr
|
|||
/**
|
||||
* A function executed when route path matched requested resource path.
|
||||
* Request handler is expected to return a result of one of {@link KibanaResponseFactory} functions.
|
||||
* If anything else is returned, or an error is thrown, the HTTP service will automatically log the error
|
||||
* and respond `500 - Internal Server Error`.
|
||||
* @param context {@link RequestHandlerContext} - the core context exposed for this request.
|
||||
* @param request {@link KibanaRequest} - object containing information about requested resource,
|
||||
* such as path, method, headers, parameters, query, body, etc.
|
||||
|
|
|
@ -1276,7 +1276,6 @@ export const kibanaResponseFactory: {
|
|||
forbidden: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
notFound: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
conflict: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
internalError: (options?: ErrorHttpResponseOptions) => KibanaResponse<ResponseError>;
|
||||
customError: (options: CustomHttpResponseOptions<ResponseError>) => KibanaResponse<ResponseError>;
|
||||
redirected: (options: RedirectResponseOptions) => KibanaResponse<string | Record<string, any> | Buffer | Stream>;
|
||||
ok: (options?: HttpResponseOptions) => KibanaResponse<string | Record<string, any> | Buffer | Stream>;
|
||||
|
@ -3197,7 +3196,7 @@ export const validBodyOutput: readonly ["data", "stream"];
|
|||
|
||||
// Warnings were encountered during analysis:
|
||||
//
|
||||
// src/core/server/http/router/response.ts:306:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts
|
||||
// src/core/server/http/router/response.ts:297:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts
|
||||
// src/core/server/plugins/types.ts:280:3 - (ae-forgotten-export) The symbol "KibanaConfigType" needs to be exported by the entry point index.d.ts
|
||||
// src/core/server/plugins/types.ts:280:3 - (ae-forgotten-export) The symbol "SharedGlobalConfigKeys" needs to be exported by the entry point index.d.ts
|
||||
// src/core/server/plugins/types.ts:283:3 - (ae-forgotten-export) The symbol "SavedObjectsConfigType" needs to be exported by the entry point index.d.ts
|
||||
|
|
|
@ -57,7 +57,6 @@ export function registerValueSuggestionsRoute(
|
|||
const field = indexPattern && getFieldByName(fieldName, indexPattern);
|
||||
const body = await getBody(autocompleteSearchOptions, field || fieldName, query, filters);
|
||||
|
||||
try {
|
||||
const result = await client.callAsCurrentUser('search', { index, body }, { signal });
|
||||
|
||||
const buckets: any[] =
|
||||
|
@ -65,9 +64,6 @@ export function registerValueSuggestionsRoute(
|
|||
get(result, 'aggregations.nestedSuggestions.suggestions.buckets');
|
||||
|
||||
return response.ok({ body: map(buckets || [], 'key') });
|
||||
} catch (error) {
|
||||
return response.internalError({ body: error });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -38,5 +38,5 @@ export const handleEsError = ({
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
};
|
||||
|
|
|
@ -136,8 +136,7 @@ export function createInstallRoute(
|
|||
(counts as any)[index] = count;
|
||||
} catch (err) {
|
||||
const errMsg = `sample_data install errors while loading data. Error: ${err}`;
|
||||
logger.warn(errMsg);
|
||||
return res.internalError({ body: errMsg });
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,8 +156,7 @@ export function createInstallRoute(
|
|||
);
|
||||
} catch (err) {
|
||||
const errMsg = `bulkCreate failed, error: ${err.message}`;
|
||||
logger.warn(errMsg);
|
||||
return res.internalError({ body: errMsg });
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
const errors = createResults.saved_objects.filter((savedObjectCreateResult) => {
|
||||
return Boolean(savedObjectCreateResult.error);
|
||||
|
|
|
@ -77,7 +77,6 @@ export function runRoute(
|
|||
},
|
||||
},
|
||||
router.handleLegacyErrors(async (context, request, response) => {
|
||||
try {
|
||||
const [, { data }] = await core.getStartServices();
|
||||
const uiSettings = await context.core.uiSettings.client.getAll();
|
||||
const indexPatternsService = await data.indexPatterns.indexPatternsServiceFactory(
|
||||
|
@ -104,19 +103,6 @@ export function runRoute(
|
|||
stats: chainRunner.getStats(),
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(`${err.toString()}: ${err.stack}`);
|
||||
// TODO Maybe we should just replace everywhere we throw with Boom? Probably.
|
||||
if (err.isBoom) {
|
||||
throw err;
|
||||
} else {
|
||||
return response.internalError({
|
||||
body: {
|
||||
message: err.toString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -42,18 +42,12 @@ export const visDataRoutes = (router: VisTypeTimeseriesRouter, framework: Framew
|
|||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const results = await getVisData(
|
||||
requestContext,
|
||||
request as KibanaRequest<{}, {}, GetVisDataOptions>,
|
||||
framework
|
||||
);
|
||||
return response.ok({ body: results });
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ export class NewsFeedSimulatorPlugin implements Plugin {
|
|||
options: { authRequired: false },
|
||||
},
|
||||
(context, req, res) => {
|
||||
return res.internalError({ body: new Error('Internal server error') });
|
||||
throw new Error('Internal server error');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export class CorePluginBPlugin implements Plugin {
|
|||
public setup(core: CoreSetup, deps: {}) {
|
||||
const router = core.http.createRouter<PluginBContext>();
|
||||
router.get({ path: '/core_plugin_b', validate: false }, async (context, req, res) => {
|
||||
if (!context.pluginA) return res.internalError({ body: 'pluginA is disabled' });
|
||||
if (!context.pluginA) throw new Error('pluginA is disabled');
|
||||
const response = await context.pluginA.ping();
|
||||
return res.ok({ body: `Pong via plugin A: ${response}` });
|
||||
});
|
||||
|
|
|
@ -50,11 +50,7 @@ export const registerCreateTokenRoute = (router: BeatsManagementRouter) => {
|
|||
});
|
||||
} catch (err) {
|
||||
beatsManagement.framework.log(err.message);
|
||||
return response.internalError({
|
||||
body: {
|
||||
message: 'An error occurred, please check your Kibana logs',
|
||||
},
|
||||
});
|
||||
throw new Error('An error occurred, please check your Kibana logs');
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -20,7 +20,7 @@ export const catchErrorHandler: <P, Q, B>(
|
|||
statusCode: error.output.statusCode,
|
||||
});
|
||||
}
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -147,8 +147,8 @@ describe('Retrieve ES Fields', () => {
|
|||
|
||||
callAsCurrentUserMock.mockRejectedValueOnce(new Error('Index not found'));
|
||||
|
||||
const response = await routeHandler(mockRouteContext, request, kibanaResponseFactory);
|
||||
|
||||
expect(response.status).toBe(500);
|
||||
await expect(
|
||||
routeHandler(mockRouteContext, request, kibanaResponseFactory)
|
||||
).rejects.toThrowError('Index not found');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -55,7 +55,7 @@ export const registerCreateRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ export const registerCreateRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -41,7 +41,7 @@ export const registerDeleteRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
return response.customError({ statusCode: 500, body: err });
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -37,7 +37,7 @@ export const registerFetchRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -48,7 +48,7 @@ export const registerGetRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -40,7 +40,7 @@ export const registerPauseRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
return response.customError({ statusCode: 500, body: err });
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -40,7 +40,7 @@ export const registerResumeRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
return response.customError({ statusCode: 500, body: err });
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -54,7 +54,7 @@ export const registerUpdateRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -64,7 +64,7 @@ export const registerPermissionsRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -36,7 +36,7 @@ export const registerStatsRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -59,7 +59,7 @@ export const registerCreateRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -56,7 +56,7 @@ export const registerFetchRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -72,7 +72,7 @@ export const registerGetRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export const registerPauseRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
return response.customError({ statusCode: 500, body: err });
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -38,7 +38,7 @@ export const registerResumeRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
return response.customError({ statusCode: 500, body: err });
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -39,7 +39,7 @@ export const registerUnfollowRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
return response.customError({ statusCode: 500, body: err });
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
|
|
|
@ -87,7 +87,7 @@ export const registerUpdateRoute = ({
|
|||
return response.customError(formatEsError(err));
|
||||
}
|
||||
// Case: default
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { MockRouter, mockLogger, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { loggingSystemMock, savedObjectsServiceMock } from 'src/core/server/mocks';
|
||||
import { savedObjectsServiceMock } from 'src/core/server/mocks';
|
||||
|
||||
jest.mock('../../collectors/lib/telemetry', () => ({
|
||||
incrementUICounter: jest.fn(),
|
||||
|
@ -84,17 +84,17 @@ describe('Enterprise Search Telemetry API', () => {
|
|||
it('throws an error when incrementing fails', async () => {
|
||||
(incrementUICounter as jest.Mock).mockImplementation(jest.fn(() => Promise.reject('Failed')));
|
||||
|
||||
await mockRouter.callRoute({
|
||||
await expect(
|
||||
mockRouter.callRoute({
|
||||
body: {
|
||||
product: 'enterprise_search',
|
||||
action: 'error',
|
||||
metric: 'error',
|
||||
},
|
||||
});
|
||||
})
|
||||
).rejects.toEqual('Failed');
|
||||
|
||||
expect(incrementUICounter).toHaveBeenCalled();
|
||||
expect(mockLogger.error).toHaveBeenCalled();
|
||||
expect(mockRouter.response.internalError).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws an error if the Saved Objects service is unavailable', async () => {
|
||||
|
@ -104,16 +104,9 @@ describe('Enterprise Search Telemetry API', () => {
|
|||
getSavedObjectsService: null,
|
||||
log: mockLogger,
|
||||
} as any);
|
||||
await mockRouter.callRoute({});
|
||||
await expect(mockRouter.callRoute({})).rejects.toThrow();
|
||||
|
||||
expect(incrementUICounter).not.toHaveBeenCalled();
|
||||
expect(mockLogger.error).toHaveBeenCalled();
|
||||
expect(mockRouter.response.internalError).toHaveBeenCalled();
|
||||
expect(loggingSystemMock.collect(mockLogger).error[0][0]).toEqual(
|
||||
expect.stringContaining(
|
||||
'Enterprise Search UI telemetry error: Error: Could not find Saved Objects service'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
|
|
|
@ -20,7 +20,7 @@ const productToTelemetryMap = {
|
|||
workplace_search: WS_TELEMETRY_NAME,
|
||||
};
|
||||
|
||||
export function registerTelemetryRoute({ router, getSavedObjectsService, log }: RouteDependencies) {
|
||||
export function registerTelemetryRoute({ router, getSavedObjectsService }: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/api/enterprise_search/stats',
|
||||
|
@ -43,7 +43,6 @@ export function registerTelemetryRoute({ router, getSavedObjectsService, log }:
|
|||
async (ctx, request, response) => {
|
||||
const { product, action, metric } = request.body;
|
||||
|
||||
try {
|
||||
if (!getSavedObjectsService) throw new Error('Could not find Saved Objects service');
|
||||
|
||||
return response.ok({
|
||||
|
@ -54,12 +53,6 @@ export function registerTelemetryRoute({ router, getSavedObjectsService, log }:
|
|||
metric,
|
||||
}),
|
||||
});
|
||||
} catch (e) {
|
||||
log.error(
|
||||
`Enterprise Search UI telemetry error: ${e instanceof Error ? e.stack : e.toString()}`
|
||||
);
|
||||
return response.internalError({ body: 'Enterprise Search UI telemetry failed' });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -76,11 +76,7 @@ export function registerExploreRoute({
|
|||
}
|
||||
}
|
||||
|
||||
return response.internalError({
|
||||
body: {
|
||||
message: error.message,
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -71,7 +71,7 @@ export const registerCreateRoute = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -54,7 +54,7 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -94,7 +94,7 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -64,7 +64,7 @@ export const registerPrivilegesRoute = ({ license, router, config }: RouteDepend
|
|||
|
||||
return res.ok({ body: privilegesResult });
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -55,7 +55,7 @@ export const registerUpdateRoute = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export function registerClearCacheRoute({ router, license, lib }: RouteDependenc
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export function registerCloseRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export function registerDeleteRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export function registerFlushRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -45,7 +45,7 @@ export function registerForcemergeRoute({ router, license, lib }: RouteDependenc
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -40,7 +40,7 @@ export function registerFreezeRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -27,7 +27,7 @@ export function registerListRoute({ router, license, indexDataEnricher, lib }: R
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export function registerOpenRoute({ router, license, lib }: RouteDependencies) {
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -38,7 +38,7 @@ export function registerRefreshRoute({ router, license, lib }: RouteDependencies
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -43,7 +43,7 @@ export function registerReloadRoute({
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -35,7 +35,7 @@ export function registerUnfreezeRoute({ router, license, lib }: RouteDependencie
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -47,7 +47,7 @@ export function registerMappingRoute({ router, license, lib }: RouteDependencies
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -48,7 +48,7 @@ export function registerLoadRoute({ router, license, lib }: RouteDependencies) {
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -46,7 +46,7 @@ export function registerUpdateRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -47,7 +47,7 @@ export function registerStatsRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -73,7 +73,7 @@ export function registerCreateRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -109,7 +109,7 @@ export function registerGetOneRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -40,7 +40,7 @@ export function registerSimulateRoute({ router, license, lib }: RouteDependencie
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -66,7 +66,7 @@ export function registerUpdateRoute({ router, license, lib }: RouteDependencies)
|
|||
});
|
||||
}
|
||||
// Case: default
|
||||
return res.internalError({ body: e });
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -33,7 +33,6 @@ export const initInventoryMetaRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const { sourceId, nodeType, currentTime } = pipe(
|
||||
InventoryMetaRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -55,11 +54,6 @@ export const initInventoryMetaRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: InventoryMetaResponseRT.encode(awsMetadata),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -31,7 +31,6 @@ export const initValidateLogAnalysisIndicesRoute = ({ framework }: InfraBackendL
|
|||
validate: { body: escapeHatch },
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const payload = pipe(
|
||||
validationIndicesRequestPayloadRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -85,11 +84,6 @@ export const initValidateLogAnalysisIndicesRoute = ({ framework }: InfraBackendL
|
|||
return response.ok({
|
||||
body: validationIndicesResponsePayloadRT.encode({ data: { errors } }),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -33,7 +33,6 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa
|
|||
validate: { body: escapeHatch },
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const payload = pipe(
|
||||
logEntriesHighlightsRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -97,11 +96,6 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa
|
|||
}),
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -33,7 +33,6 @@ export const initLogEntriesSummaryRoute = ({ framework, logEntries }: InfraBacke
|
|||
validate: { body: escapeHatch },
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const payload = pipe(
|
||||
logEntriesSummaryRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -60,11 +59,6 @@ export const initLogEntriesSummaryRoute = ({ framework, logEntries }: InfraBacke
|
|||
},
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -35,19 +35,11 @@ export const initLogEntriesSummaryHighlightsRoute = ({
|
|||
validate: { body: escapeHatch },
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const payload = pipe(
|
||||
logEntriesSummaryHighlightsRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
);
|
||||
const {
|
||||
sourceId,
|
||||
startTimestamp,
|
||||
endTimestamp,
|
||||
bucketSize,
|
||||
query,
|
||||
highlightTerms,
|
||||
} = payload;
|
||||
const { sourceId, startTimestamp, endTimestamp, bucketSize, query, highlightTerms } = payload;
|
||||
|
||||
const bucketsPerHighlightTerm = await logEntries.getLogSummaryHighlightBucketsBetween(
|
||||
requestContext,
|
||||
|
@ -68,11 +60,6 @@ export const initLogEntriesSummaryHighlightsRoute = ({
|
|||
})),
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -37,7 +37,6 @@ export const initMetadataRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const { nodeId, nodeType, sourceId, timeRange } = pipe(
|
||||
InfraMetadataRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -55,9 +54,7 @@ export const initMetadataRoute = (libs: InfraBackendLibs) => {
|
|||
nodeType,
|
||||
timeRange
|
||||
);
|
||||
const metricFeatures = pickFeatureName(metricsMetadata.buckets).map(
|
||||
nameToFeature('metrics')
|
||||
);
|
||||
const metricFeatures = pickFeatureName(metricsMetadata.buckets).map(nameToFeature('metrics'));
|
||||
|
||||
const info = await getNodeInfo(
|
||||
framework,
|
||||
|
@ -91,11 +88,6 @@ export const initMetadataRoute = (libs: InfraBackendLibs) => {
|
|||
info,
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -29,7 +29,6 @@ export const initMetricsAPIRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const options = pipe(
|
||||
MetricsAPIRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -41,11 +40,6 @@ export const initMetricsAPIRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: MetricsAPIResponseRT.encode(metricsApiResponse),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -37,7 +37,6 @@ export const initMetricExplorerRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const options = pipe(
|
||||
metricsExplorerRequestBodyRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -81,11 +80,6 @@ export const initMetricExplorerRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: metricsExplorerResponseRT.encode({ series, pageInfo }),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -34,7 +34,6 @@ export const initNodeDetailsRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const { nodeId, cloudId, nodeType, metrics, timerange, sourceId } = pipe(
|
||||
NodeDetailsRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -61,11 +60,6 @@ export const initNodeDetailsRoute = (libs: InfraBackendLibs) => {
|
|||
metrics: await libs.metrics.getMetrics(requestContext, options, request),
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -36,7 +36,6 @@ export const initOverviewRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const overviewRequest = pipe(
|
||||
OverviewRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -102,11 +101,6 @@ export const initOverviewRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -35,7 +35,6 @@ export const initProcessListRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const options = pipe(
|
||||
ProcessListAPIRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -47,11 +46,6 @@ export const initProcessListRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: ProcessListAPIResponseRT.encode(processListResponse),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -64,7 +58,6 @@ export const initProcessListRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const options = pipe(
|
||||
ProcessListAPIChartRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -76,11 +69,6 @@ export const initProcessListRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: ProcessListAPIChartResponseRT.encode(processListResponse),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -31,7 +31,6 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const snapshotRequest = pipe(
|
||||
SnapshotRequestRT.decode(request.body),
|
||||
fold(throwErrors(Boom.badRequest), identity)
|
||||
|
@ -49,11 +48,6 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: SnapshotNodeResponseRT.encode(snapshotResponse),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -44,7 +44,6 @@ export const initSourceRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const { type, sourceId } = request.params;
|
||||
|
||||
const [source, logIndexStatus, metricIndicesExist, indexFields] = await Promise.all([
|
||||
|
@ -67,11 +66,6 @@ export const initSourceRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: SourceResponseRuntimeType.encode({ source: { ...source, status } }),
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -169,7 +163,6 @@ export const initSourceRoute = (libs: InfraBackendLibs) => {
|
|||
},
|
||||
},
|
||||
async (requestContext, request, response) => {
|
||||
try {
|
||||
const { type, sourceId } = request.params;
|
||||
|
||||
const client = createSearchClient(requestContext, framework);
|
||||
|
@ -184,11 +177,6 @@ export const initSourceRoute = (libs: InfraBackendLibs) => {
|
|||
return response.ok({
|
||||
body: { hasData: results },
|
||||
});
|
||||
} catch (error) {
|
||||
return response.internalError({
|
||||
body: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -83,7 +83,7 @@ export const registerCreateRoute = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -51,7 +51,7 @@ export const registerDocumentsRoute = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -44,7 +44,7 @@ export const registerGetRoutes = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -78,7 +78,7 @@ export const registerGetRoutes = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -44,7 +44,6 @@ export const registerPrivilegesRoute = ({ license, router, config }: RouteDepend
|
|||
},
|
||||
} = ctx;
|
||||
|
||||
try {
|
||||
const { has_all_requested: hasAllPrivileges, cluster } = await client.callAsCurrentUser(
|
||||
'transport.request',
|
||||
{
|
||||
|
@ -63,9 +62,6 @@ export const registerPrivilegesRoute = ({ license, router, config }: RouteDepend
|
|||
privilegesResult.hasAllPrivileges = hasAllPrivileges;
|
||||
|
||||
return res.ok({ body: privilegesResult });
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
}
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -52,7 +52,7 @@ export const registerSimulateRoute = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -65,7 +65,7 @@ export const registerUpdateRoute = ({
|
|||
});
|
||||
}
|
||||
|
||||
return res.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -77,11 +77,9 @@ export async function existingFieldsRoute(setup: CoreSetup<PluginStartContract>,
|
|||
if (e.output.statusCode === 404) {
|
||||
return res.notFound({ body: e.output.payload.message });
|
||||
}
|
||||
return res.internalError({ body: e.output.payload.message });
|
||||
throw new Error(e.output.payload.message);
|
||||
} else {
|
||||
return res.internalError({
|
||||
body: Boom.internal(e.message || e.name),
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import Boom from '@hapi/boom';
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
import DateMath from '@elastic/datemath';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
@ -111,11 +110,9 @@ export async function initFieldsRoute(setup: CoreSetup<PluginStartContract>) {
|
|||
if (e.output.statusCode === 404) {
|
||||
return res.notFound();
|
||||
}
|
||||
return res.internalError(e.output.message);
|
||||
throw new Error(e.output.message);
|
||||
} else {
|
||||
return res.internalError({
|
||||
body: Boom.internal(e.message || e.name),
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import Boom from '@hapi/boom';
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
import { CoreSetup } from 'src/core/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
@ -84,11 +83,9 @@ export async function initLensUsageRoute(setup: CoreSetup<PluginStartContract>)
|
|||
if (e.output.statusCode === 404) {
|
||||
return res.notFound();
|
||||
}
|
||||
return res.internalError(e.output.message);
|
||||
throw new Error(e.output.message);
|
||||
} else {
|
||||
return res.internalError({
|
||||
body: Boom.internal(e.message || e.name),
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ export function registerLicenseRoute({ router, plugins: { licensing } }: RouteDe
|
|||
},
|
||||
async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
try {
|
||||
return res.ok({
|
||||
body: await putLicense({
|
||||
acknowledge: Boolean(req.query.acknowledge),
|
||||
|
@ -32,9 +31,6 @@ export function registerLicenseRoute({ router, plugins: { licensing } }: RouteDe
|
|||
license: req.body,
|
||||
}),
|
||||
});
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,8 @@ export function registerPermissionsRoute({
|
|||
router.post({ path: addBasePath('/permissions'), validate: false }, async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
|
||||
try {
|
||||
return res.ok({
|
||||
body: await getPermissions({ callAsCurrentUser, isSecurityEnabled }),
|
||||
});
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ export function registerStartBasicRoute({ router, plugins: { licensing } }: Rout
|
|||
},
|
||||
async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
try {
|
||||
return res.ok({
|
||||
body: await startBasic({
|
||||
acknowledge: Boolean(req.query.acknowledge),
|
||||
|
@ -26,9 +25,6 @@ export function registerStartBasicRoute({ router, plugins: { licensing } }: Rout
|
|||
licensing,
|
||||
}),
|
||||
});
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,21 +12,13 @@ import { addBasePath } from '../../helpers';
|
|||
export function registerStartTrialRoutes({ router, plugins: { licensing } }: RouteDependencies) {
|
||||
router.get({ path: addBasePath('/start_trial'), validate: false }, async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
try {
|
||||
return res.ok({ body: await canStartTrial(callAsCurrentUser) });
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
}
|
||||
});
|
||||
|
||||
router.post({ path: addBasePath('/start_trial'), validate: false }, async (ctx, req, res) => {
|
||||
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
|
||||
try {
|
||||
return res.ok({
|
||||
body: await startTrial({ callAsCurrentUser, licensing }),
|
||||
});
|
||||
} catch (e) {
|
||||
return res.internalError({ body: e });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ export function registerClusterLoadRoute(router: LogstashPluginRouter) {
|
|||
if (err.status === 403) {
|
||||
return response.ok();
|
||||
}
|
||||
return response.internalError();
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -372,7 +372,7 @@ export class MonitoringPlugin
|
|||
if (Boom.isBoom(err) || statusCode !== 500) {
|
||||
return res.customError({ statusCode, body: err });
|
||||
}
|
||||
return res.internalError(wrapError(err));
|
||||
throw wrapError(err).body;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ export const register = (deps: RouteDependencies): void => {
|
|||
if (isEsError(error)) {
|
||||
return response.customError({ statusCode: error.statusCode, body: error });
|
||||
}
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
deps.router.post(
|
||||
|
|
|
@ -95,7 +95,7 @@ export const register = (deps: RouteDependencies): void => {
|
|||
if (isEsError(error)) {
|
||||
return response.customError({ statusCode: error.statusCode, body: error });
|
||||
}
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -132,7 +132,7 @@ export const register = (deps: RouteDependencies): void => {
|
|||
if (isEsError(error)) {
|
||||
return response.customError({ statusCode: error.statusCode, body: error });
|
||||
}
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -78,10 +78,16 @@ describe('GET remote clusters', () => {
|
|||
const mockContext = xpackMocks.createRequestHandlerContext();
|
||||
mockContext.core.elasticsearch.legacy.client = mockScopedClusterClient;
|
||||
|
||||
if (asserts.statusCode === 500) {
|
||||
await expect(handler(mockContext, mockRequest, kibanaResponseFactory)).rejects.toThrowError(
|
||||
asserts.result as Error
|
||||
);
|
||||
} else {
|
||||
const response = await handler(mockContext, mockRequest, kibanaResponseFactory);
|
||||
|
||||
expect(response.status).toBe(asserts.statusCode);
|
||||
expect(response.payload).toEqual(asserts.result);
|
||||
}
|
||||
|
||||
if (Array.isArray(asserts.apiArguments)) {
|
||||
for (const apiArguments of asserts.apiArguments) {
|
||||
|
|
|
@ -63,7 +63,7 @@ export const register = (deps: RouteDependencies): void => {
|
|||
if (isEsError(error)) {
|
||||
return response.customError({ statusCode: error.statusCode, body: error });
|
||||
}
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ export const register = (deps: RouteDependencies): void => {
|
|||
if (isEsError(error)) {
|
||||
return response.customError({ statusCode: error.statusCode, body: error });
|
||||
}
|
||||
return response.internalError({ body: error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ export const registerGetRoute = ({
|
|||
if (isEsError(err)) {
|
||||
return response.customError({ statusCode: err.statusCode, body: err });
|
||||
}
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -136,7 +136,7 @@ export const registerValidateIndexPatternRoute = ({
|
|||
return response.customError({ statusCode: err.statusCode, body: err });
|
||||
}
|
||||
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -43,7 +43,7 @@ export const registerCreateRoute = ({
|
|||
if (isEsError(err)) {
|
||||
return response.customError({ statusCode: err.statusCode, body: err });
|
||||
}
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -45,7 +45,7 @@ export const registerDeleteRoute = ({
|
|||
if (isEsError(err)) {
|
||||
return response.customError({ statusCode: err.statusCode, body: err });
|
||||
}
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
@ -26,7 +26,7 @@ export const registerGetRoute = ({
|
|||
if (isEsError(err)) {
|
||||
return response.customError({ statusCode: err.statusCode, body: err });
|
||||
}
|
||||
return response.internalError({ body: err });
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue