From aa46eb26d45012036c69c524db512ed16fde7b6b Mon Sep 17 00:00:00 2001 From: Yiyu He Date: Mon, 22 Jan 2018 10:12:23 +0800 Subject: [PATCH] fix: log cookie's key when cookie exceed limit length (#1996) --- lib/application.js | 1 + test/lib/application.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/application.js b/lib/application.js index d521fae52a..63a3de57dc 100644 --- a/lib/application.js +++ b/lib/application.js @@ -271,6 +271,7 @@ class Application extends EggApplication { this.on('cookieLimitExceed', ({ name, value, ctx }) => { const err = new Error(`cookie ${name}'s length(${value.length}) exceed the limit(4093)`); err.name = 'CookieLimitExceedError'; + err.key = name; err.cookie = value; ctx.coreLogger.error(err); }); diff --git a/test/lib/application.test.js b/test/lib/application.test.js index a18e686aaf..3e0c19c7ca 100644 --- a/test/lib/application.test.js +++ b/test/lib/application.test.js @@ -200,5 +200,21 @@ describe('test/lib/application.test.js', () => { .expect(200); }); }); + + describe('on cookieLimitExceed', () => { + it('should log error', done => { + const ctx = { + coreLogger: { + error(err) { + assert(err.key === 'name'); + assert(err.cookie === 'value'); + assert(err.name === 'CookieLimitExceedError'); + done(); + }, + }, + }; + app.emit('cookieLimitExceed', { name: 'name', value: 'value', ctx }); + }); + }); }); });