Skip to content

Commit

Permalink
fix: log cookie's key when cookie exceed limit length (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored Jan 22, 2018
1 parent 7993b45 commit aa46eb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
16 changes: 16 additions & 0 deletions test/lib/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});
});
});

0 comments on commit aa46eb2

Please sign in to comment.