Skip to content

Commit

Permalink
fix(fixes): ZMS-185 (#31)
Browse files Browse the repository at this point in the history
* fix logical error with tempfail

* fix subject issue when using api. add debugJson to gelf

* safer delete with check
  • Loading branch information
NickOvt authored Nov 7, 2024
1 parent 8f9d759 commit 0a74d1f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module.exports.init = async app => {
const originhost = serverHost || (envelope.originhost || '').replace('[', '').replace(']', '');
const transhost = (envelope.transhost || '').replace('[', '').replace(']', '') || originhost;

let subject = messageinfo.subject || 'no subject';
let subject = messageinfo.subject || allHeadersParsed.Subject || 'no subject';
subject = subject.substring(0, subjectMaxLength);
const messageIdHeaderVal = allHeadersParsed['Message-ID']?.replace('<', '').replace('>', '');

Expand All @@ -218,6 +218,15 @@ module.exports.init = async app => {
});
const resBodyJson = await res.body.json();

const debugJson = { ...resBodyJson };

['SENDER', 'SENDER_GROUP', 'WEBHOOK'].forEach(sym => {
if (debugJson.symbols) {
delete debugJson.symbols[sym];
}
});
['sender', 'action', 'zilter-id', 'client'].forEach(el => delete debugJson[el]);

if (res.statusCode === 401) {
// unauthorized Zilter, default to tempfail error return
loggelfForEveryUser(app, subject, {
Expand All @@ -233,7 +242,8 @@ module.exports.init = async app => {
_subject: subject,
level: 5,
_zilter_error: 'Unauthorized error 401',
_ip: envelope.origin
_ip: envelope.origin,
_debug_json: debugJson
});
}

Expand All @@ -258,7 +268,8 @@ module.exports.init = async app => {
level: 5,
_passed: 'N',
_action: resBodyJson.action,
_ip: envelope.origin
_ip: envelope.origin,
_debug_json: debugJson
});
} else if (resBodyJson.action && resBodyJson.action === 'accept') {
// accepted, so not a tempfail
Expand All @@ -276,7 +287,8 @@ module.exports.init = async app => {
_subject: subject,
level: 5,
_passed: 'Y',
_ip: envelope.origin
_ip: envelope.origin,
_debug_json: debugJson
});
}
} catch (err) {
Expand Down

0 comments on commit 0a74d1f

Please sign in to comment.