Skip to content

Commit

Permalink
Remove the default value of response data
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnysunny committed Jul 15, 2020
1 parent ce03a0c commit 21f5793
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.12.1
## Remove
1. Remove the default value of response data. You should avoid reading undefined object in `dataFormat` function when format response data.

# v0.12.0
## Add
1. Add the field of `res_data`, which contains the reponse data.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = function({
const req_data = dataFormat(req_data_original);
const referer = req.get('referer') || '';
const session = req.session;
const res_data = dataFormat(res._res_data || {}, true);
const res_data = dataFormat(res._res_data, true);

if (kafkaSchedule || mongooseModel) {
const custom_headers = {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yunnysunny/request-logging",
"version": "0.12.0",
"version": "0.12.1",
"description": "Print the express request log to console and save it to kafka when required, and even can send alram message when the response code greater than 500.",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion test/express/src/app-with-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ app.set('port', port);
app.use(requestLog({
mongooseModel:requestLogModel,
customHeaderKeys: [CUSTOM_HEADER_KEY_MY_ID],
dataFormat: function(data) {
dataFormat: function(data, isFromRes) {
if (isFromRes) {
return;
}
data[TO_FORMAT_FIELD] = (data[TO_FORMAT_FIELD] || '') + FORMAT_SUFFIX;
return data;
}
Expand Down

0 comments on commit 21f5793

Please sign in to comment.