Revert 165293 (#166077)

## Summary

Let's revert https://github.com/elastic/kibana/pull/165293 until we
agree on the attributes of the error object that we want to log. Should
they be based on the `EcsError` interface?
This commit is contained in:
Gerard Soldevila 2023-09-08 20:45:40 +02:00 committed by GitHub
parent 3735645f5a
commit e34f9ce937
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 28 deletions

View file

@ -201,7 +201,6 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo
kibanaRequest = CoreKibanaRequest.from(request, routeSchemas);
} catch (error) {
this.log.error(`400 Bad Request - ${request.path}`, {
error,
http: { response: { status_code: 400 } },
});
@ -218,7 +217,6 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo
// forward 401 errors from ES client
if (isElasticsearchUnauthorizedError(error)) {
this.log.error(`401 Unauthorized - ${request.path}`, {
error,
http: { response: { status_code: 401 } },
});
return hapiResponseAdapter.handle(
@ -228,7 +226,6 @@ export class Router<Context extends RequestHandlerContextBase = RequestHandlerCo
// return a generic 500 to avoid error info / stack trace surfacing
this.log.error(`500 Server Error - ${request.path}`, {
error,
http: { response: { status_code: 500 } },
});
return hapiResponseAdapter.toInternalError();

View file

@ -568,6 +568,7 @@ describe('Handler', () => {
router.get({ path: '/', validate: false }, (context, req, res) => {
throw new Error('unexpected error');
});
await server.start();
const result = await supertest(innerServer.listener).get('/').expect(500);
@ -575,21 +576,9 @@ describe('Handler', () => {
expect(result.body.message).toBe(
'An internal server error occurred. Check Kibana server logs for details.'
);
expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(`
Array [
Array [
"500 Server Error - /",
Object {
"error": [Error: unexpected error],
"http": Object {
"response": Object {
"status_code": 500,
},
},
},
],
]
`);
const [message] = loggingSystemMock.collect(logger).error[0];
expect(message).toEqual('500 Server Error - /');
});
it('captures the error if handler throws', async () => {
@ -627,7 +616,6 @@ describe('Handler', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: Unauthorized],
"http": Object {
"response": Object {
"status_code": 500,
@ -657,7 +645,6 @@ describe('Handler', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: Unexpected result from Route Handler. Expected KibanaResponse, but given: string.],
"http": Object {
"response": Object {
"status_code": 500,
@ -702,7 +689,6 @@ describe('Handler', () => {
Array [
"400 Bad Request - /",
Object {
"error": [Error: [request query.page]: expected value of type [number] but got [string]],
"http": Object {
"response": Object {
"status_code": 400,
@ -1187,7 +1173,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: expected 'location' header to be set],
"http": Object {
"response": Object {
"status_code": 500,
@ -1601,7 +1586,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: Unexpected Http status code. Expected from 400 to 599, but given: 200],
"http": Object {
"response": Object {
"status_code": 500,
@ -1678,7 +1662,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: expected 'location' header to be set],
"http": Object {
"response": Object {
"status_code": 500,
@ -1826,7 +1809,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: expected error message to be provided],
"http": Object {
"response": Object {
"status_code": 500,
@ -1860,7 +1842,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: expected error message to be provided],
"http": Object {
"response": Object {
"status_code": 500,
@ -1893,7 +1874,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: options.statusCode is expected to be set. given options: undefined],
"http": Object {
"response": Object {
"status_code": 500,
@ -1926,7 +1906,6 @@ describe('Response factory', () => {
Array [
"500 Server Error - /",
Object {
"error": [Error: Unexpected Http status code. Expected from 100 to 599, but given: 20.],
"http": Object {
"response": Object {
"status_code": 500,