Skip to content

Commit

Permalink
Merge pull request #1537 from telefonicaid/task/badtimestamp_error_log
Browse files Browse the repository at this point in the history
Task/badtimestamp error log (hotfix 4.0.0)
  • Loading branch information
fgalan authored Nov 29, 2023
2 parents f190ec3 + 3586504 commit e29a720
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
Empty file removed CHANGES_NEXT_RELEASE
Empty file.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "iotagent-node-lib",
"license": "AGPL-3.0-only",
"description": "IoT Agent library to interface with NGSI Context Broker",
"version": "4.0.0",
"version": "4.0.1",
"homepage": "https://github.com/telefonicaid/iotagent-node-lib",
"keywords": [
"fiware",
Expand Down

0 comments on commit e29a720

Please sign in to comment.