Skip to content

Commit

Permalink
log detail when badTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Nov 29, 2023
1 parent dc58c63 commit 5d34f31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ class BadAnswer {
}
}
class BadTimestamp {
constructor(payload) {
constructor(payload, entityName) {
this.name = 'BAD_TIMESTAMP';
this.message = 'Invalid ISO8601 timestamp [' + payload + ']';
this.message = 'Invalid ISO8601 timestamp [' + payload + '] in [' + entityName + ']';
this.code = 400;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/ngsi/entities-NGSI-LD.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
} else if (!utils.IsValidTimestampedNgsi2(payload[n])) {
// legacy check needed?
logger.error(context, 'Invalid timestamp:%s', JSON.stringify(payload[0]));
callback(new errors.BadTimestamp(payload));
callback(new errors.BadTimestamp(payload, entityName));
return;
}
}
Expand Down
30 changes: 13 additions & 17 deletions lib/services/ngsi/entities-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call
if (moment(plainMeasures[constants.TIMESTAMP_ATTRIBUTE], moment.ISO_8601, true).isValid()) {
timestamp.value = plainMeasures[constants.TIMESTAMP_ATTRIBUTE];
} else {
callback(new errors.BadTimestamp(null, entityName));
callback(new errors.BadTimestamp(plainMeasures[constants.TIMESTAMP_ATTRIBUTE], entityName));
}
} else if (!typeInformation.timezone) {
timestamp.value = new Date().toISOString();
Expand Down Expand Up @@ -387,10 +387,11 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call
typeof currentAttr.entity_name == 'string'
) {
try {
logger.debug(context,
logger.debug(
context,
'Evaluating attribute: %j, for entity_name(exp):%j, with ctxt: %j',
currentAttr.name,
currentAttr.entity_name,
currentAttr.name,
currentAttr.entity_name,
jexlctxt
);
attrEntityName = jexlParser.applyExpression(currentAttr.entity_name, jexlctxt, typeInformation);
Expand Down Expand Up @@ -451,10 +452,11 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call
} catch (e) {
valueExpression = null;
}
logger.debug(context,
'Evaluated attr: %j, with expression: %j, and ctxt: %j resulting: %j',
logger.debug(
context,
'Evaluated attr: %j, with expression: %j, and ctxt: %j resulting: %j',
currentAttr.name,
currentAttr.expression,
currentAttr.expression,
jexlctxt,
valueExpression
);
Expand Down Expand Up @@ -564,7 +566,7 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call
}
}
}

let url = '/v2/op/update';
let options = NGSIUtils.createRequestObject(url, typeInformation, token);
options.json = payload;
Expand Down Expand Up @@ -607,15 +609,9 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call
} // else: keep current options object created for a batch update

//Send the NGSI request
logger.debug(context,
'Updating device value in the Context Broker at: %j',
options.url
);
logger.debug(context,
'Using the following NGSI v2 request: %j',
options
);

logger.debug(context, 'Updating device value in the Context Broker at: %j', options.url);
logger.debug(context, 'Using the following NGSI v2 request: %j', options);

request(
options,
generateNGSI2OperationHandler('update', entityName, typeInformation, token, options, callback)
Expand Down

0 comments on commit 5d34f31

Please sign in to comment.