From 6edcbd7b796811b0041de2ab9ef2afdd2589624d Mon Sep 17 00:00:00 2001 From: Ruslan Lopatin Date: Sun, 8 Nov 2020 16:38:18 +0700 Subject: [PATCH] Do not add method and URL prefix when logging error --- src/http/http-listener.spec.ts | 8 ++++---- src/http/http-listener.ts | 9 +++------ src/http/request/json-parsing.capability.spec.ts | 1 - 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/http/http-listener.spec.ts b/src/http/http-listener.spec.ts index d915961..56d0f6d 100644 --- a/src/http/http-listener.spec.ts +++ b/src/http/http-listener.spec.ts @@ -183,7 +183,7 @@ describe('httpListener', () => { const response = await server.get('/test'); expect(await response.body()).toContain('ERROR test'); - expect(logErrorSpy).toHaveBeenCalledWith('[GET /test]', error); + expect(logErrorSpy).toHaveBeenCalledWith(error); expect(errorHandler).toHaveBeenCalledWith(expect.objectContaining({ request: expect.objectContaining({ method: 'GET', url: '/test' }), error, @@ -205,7 +205,7 @@ describe('httpListener', () => { const body = await response.body(); expect(body).toContain('ERROR 404 Never Found'); - expect(logErrorSpy).toHaveBeenCalledWith('[GET /test]', '404', 'Never Found'); + expect(logErrorSpy).toHaveBeenCalledWith('404', 'Never Found'); expect(errorHandler).toHaveBeenCalledWith(expect.objectContaining({ request: expect.objectContaining({ method: 'GET', url: '/test' }), error, @@ -223,7 +223,7 @@ describe('httpListener', () => { const response = await server.get('/test'); expect(await response.body()).toBe(''); - expect(logErrorSpy).toHaveBeenCalledWith('[GET /test]', error); + expect(logErrorSpy).toHaveBeenCalledWith(error); }); it('does not log ERROR when there is no error handler', async () => { @@ -256,7 +256,7 @@ describe('httpListener', () => { const response = await server.get('/test'); expect(await response.body()).toBe('NO RESPONSE'); - expect(logErrorSpy).toHaveBeenCalledWith('[GET /test]', error); + expect(logErrorSpy).toHaveBeenCalledWith(error); }); it('logs unhandled error', async () => { diff --git a/src/http/http-listener.ts b/src/http/http-listener.ts index e38fbe0..4244b3f 100644 --- a/src/http/http-listener.ts +++ b/src/http/http-listener.ts @@ -266,15 +266,12 @@ function httpErrorHandler, + { log, error }: RequestContext, ): void { - - const prefix = `[${method} ${url}]`; - if (error instanceof HttpError) { - log.error(prefix, ...error.toLog()); + log.error(...error.toLog()); } else { - log.error(prefix, error); + log.error(error); } } diff --git a/src/http/request/json-parsing.capability.spec.ts b/src/http/request/json-parsing.capability.spec.ts index 9ed8357..aa9871d 100644 --- a/src/http/request/json-parsing.capability.spec.ts +++ b/src/http/request/json-parsing.capability.spec.ts @@ -133,7 +133,6 @@ describe('JsonParsing', () => { expect(response.statusCode).toBe(400); expect(await response.body()).toContain('Malformed JSON'); expect(errorSpy).toHaveBeenCalledWith( - expect.any(String), '400', 'Malformed JSON', expect.objectContaining({ message: expect.stringContaining('Unexpected token') }),