Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Refresh Documentation
Add NGSIv2 metadata support to device provisioned attributes
Fix: Error message when sending measures with unknown/undefined attribute
Add Null check within executeWithSecurity() to avoid crash (#829)
Update NGSI support to use ES6 syntax. (#850)
NGSI-LD Command support (#848)
Basic NGSI-LD active measures support (#841)
Add GeoJSON and DateTime, unitCode and observedAt NGSI-LD support (#843)
Expand Down
4 changes: 1 addition & 3 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
* Modified by: Daniel Calvo - ATOS Research & Innovation
*/

'use strict';

const LOCATION_TYPE = 'geo:point';
const LOCATION_DEFAULT = '0, 0';
const DATETIME_TYPE = 'DateTime';
Expand Down Expand Up @@ -76,5 +74,5 @@ module.exports = {
ORION_ALARM: 'ORION-ALARM',
IOTAM_ALARM: 'IOTAM-ALARM',

getInitialValueForType: getInitialValueForType
getInitialValueForType
};
239 changes: 170 additions & 69 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,163 +23,264 @@
* Modified by: Daniel Calvo - ATOS Research & Innovation
*/

'use strict';

module.exports = {
RegistrationError: function(id, type) {
class RegistrationError {
constructor(id, type) {
this.name = 'REGISTRATION_ERROR';
this.message = 'Error registering context provider for device: ' + id + ' of type: ' + type;
},
UnregistrationError: function(id, type) {
}
}
class UnregistrationError {
constructor(id, type) {
this.name = 'UNREGISTRATION_ERROR';
this.message = 'Error unregistering context provider for device: ' + id + ' of type: ' + type;
},
EntityGenericError: function(id, type, details, code) {
}
}
class EntityGenericError {
constructor(id, type, details, code) {
this.name = 'ENTITY_GENERIC_ERROR';
this.message = 'Error accesing entity data for device: ' + id + ' of type: ' + type;
this.details = details || {};
this.code = code || 200;
},
EntityNotFound: function(id) {
}
}
class EntityNotFound {
constructor(id) {
this.name = 'ENTITY_NOT_FOUND';
this.message = 'The entity with the requested id [' + id + '] was not found.';
this.code = 404;
},
RegistryNotAvailable: function() {
}
}
class RegistryNotAvailable {
constructor() {
this.name = 'REGISTRY_NOT_AVAILABLE';
this.message = 'No device registry is available.';
},
InternalDbError: function(msg) {
}
}
class InternalDbError {
constructor(msg) {
this.name = 'INTERNAL_DB_ERROR';
this.message = 'An internal DB Error happened: ' + msg;
},
BadRequest: function(msg) {
}
}
class BadRequest {
constructor(msg) {
this.name = 'BAD_REQUEST';
this.message = 'Request error connecting to the Context Broker: ' + msg;
this.code = 400;
},
UnsupportedContentType: function(type) {
}
}
class UnsupportedContentType {
constructor(type) {
this.name = 'UNSUPPORTED_CONTENT_TYPE';
this.message = 'Unsupported content type in the context request: ' + type;
this.code = 400;
},
TypeNotFound: function(id, type) {
}
}
class TypeNotFound {
constructor(id, type) {
this.name = 'TYPE_NOT_FOUND';
this.message = 'Type : ' + type + ' not found for device with id: ' + id;
this.code = 500;
},
MissingAttributes: function(msg) {
}
}
class MissingAttributes {
constructor(msg) {
this.name = 'MISSING_ATTRIBUTES';
this.message = 'The request was not well formed:' + msg;
},
DeviceNotFound: function(id) {
}
}
class DeviceNotFound {
constructor(id) {
this.name = 'DEVICE_NOT_FOUND';
this.message = 'No device was found with id:' + id;
this.code = 404;
},
AttributeNotFound: function(){
}
}
class AttributeNotFound {
constructor() {
this.name = 'ATTRIBUTE_NOT_FOUND';
this.message = 'Some of the attributes does not exist';
this.code = 404;
},
DuplicateDeviceId: function(id) {
}
}
class DuplicateDeviceId {
constructor(id) {
this.name = 'DUPLICATE_DEVICE_ID';
this.message = 'A device with the same pair (Service, DeviceId) was found:' + id;
this.code = 409;
},
DuplicateGroup: function(res, key) {
}
}
class DuplicateGroup {
constructor(res, key) {
this.name = 'DUPLICATE_GROUP';
this.message = 'A device configuration already exists for resource ' + res + ' and API Key ' + key;
this.code = 409;
},
SecurityInformationMissing: function(type) {
}
}
class SecurityInformationMissing {
constructor(type) {
this.name = 'SECURITY_INFORMATION_MISSING';
this.message = 'Some security information was missing for device type:' + type;
},
TokenRetrievalError: function(trust, msg) {
}
}
class TokenRetrievalError {
constructor(trust, msg) {
this.name = 'TOKEN_RETRIEVAL_ERROR';
this.message = 'An error occurred trying to retrieve a token with trust [' + trust + ']: ' + msg;
},
AccessForbidden: function(token, service, subservice) {
}
}
class AccessForbidden {
constructor(token, service, subservice) {
this.name = 'ACCESS_FORBIDDEN';
this.message = 'The access to the CB was rejected for service [' +
service + '] subservice [ ' + subservice + ' ] and token [' + token + ']';
},
AuthenticationError: function(trust) {
this.message =
'The access to the CB was rejected for service [' +
service +
'] subservice [ ' +
subservice +
' ] and token [' +
token +
']';
}
}
class AuthenticationError {
constructor(trust) {
this.name = 'AUTHENTICATION_ERROR';
this.message = 'The trust configured for the device was rejected: [' + trust + ']';
},
BadConfiguration: function(msg) {
}
}
class BadConfiguration {
constructor(msg) {
this.name = 'BAD_CONFIGURATION';
this.message = 'The application startup failed due to a bad configuration:' + msg;
},
MissingHeaders: function(msg) {
}
}
class MissingHeaders {
constructor(msg) {
this.name = 'MISSING_HEADERS';
this.message = 'Some headers were missing from the request: ' + msg;
this.code = 400;
},
MismatchedService: function(service, subservice) {
}
}
class MismatchedService {
constructor(service, subservice) {
this.name = 'MISMATCHED_SERVICE';
this.message = 'The declared service didn\'t match the stored one in the entity';
this.code = 403;
},
WrongSyntax: function(msg) {
}
}
class WrongSyntax {
constructor(msg) {
this.name = 'WRONG_SYNTAX';
this.message = 'Wrong syntax in request: ' + msg;
this.code = 400;
},
CommandNotFound: function(name) {
}
}
class CommandNotFound {
constructor(name) {
this.name = 'COMMAND_NOT_FOUND';
this.message = 'Couldn\'t update the command because no command with the name [' + name + '] was found.';
this.code = 400;
},
MissingConfigParams: function(missing) {
}
}
class MissingConfigParams {
constructor(missing) {
this.name = 'MISSING_CONFIG_PARAMS';
this.message = 'The following mandatory configuration parameters were missing: ' + JSON.stringify(missing);
this.code = 400;
},
NotificationError: function(code) {
}
}
class NotificationError {
constructor(code) {
this.name = 'NOTIFICATION_ERROR';
this.message = 'Incoming notification with non-200 status code: ' + code;
this.code = 400;
},
DeviceGroupNotFound: function(fields, values) {
}
}
class DeviceGroupNotFound {
constructor(fields, values) {
this.name = 'DEVICE_GROUP_NOT_FOUND';
if (values && fields) {
this.message = 'Couldn\t find device group for fields: ' + fields + ' and values: ' + values;
} else {
this.message = 'Couldn\t find device group';
}
this.code = 404;
},
GroupNotFound: function(service, subservice) {
}
}
class GroupNotFound {
constructor(service, subservice) {
this.name = 'GROUP_NOT_FOUND';
this.message = 'Group not found for service [' + service + '] and subservice [' + subservice + ']';
this.code = 404;
},
WrongExpressionType: function(type) {
}
}
class WrongExpressionType {
constructor(type) {
this.name = 'WRONG_EXPRESSION_TYPE';
this.message = 'Invalid type evaluating expression [' + type + ']';
this.code = 400;
},
InvalidExpression: function(expression) {
}
}
class InvalidExpression {
constructor(expression) {
this.name = 'INVALID_EXPRESSION';
this.message = 'Invalid expression in evaluation [' + expression + ']';
this.code = 400;
},
BadAnswer: function(statusCode, operation) {
}
}
class BadAnswer {
constructor(statusCode, operation) {
this.name = 'BAD_ANSWER';
this.message = 'Invalid statusCode in operation [' + operation + ']';
this.code = 400;
},
BadTimestamp: function(payload) {
}
}
class BadTimestamp {
constructor(payload) {
this.name = 'BAD_TIMESTAMP';
this.message = 'Invalid ISO8601 timestamp [' + payload + ']';
this.code = 400;
},
BadGeocoordinates: function(payload) {
}
}
class BadGeocoordinates {
constructor(payload) {
this.name = 'BAD_GEOCOORDINATES';
this.message = 'Invalid rfc7946 coordinates [' + payload + ']';
this.code = 400;
}
};
}

module.exports = {
RegistrationError,
UnregistrationError,
EntityGenericError,
EntityNotFound,
RegistryNotAvailable,
InternalDbError,
BadRequest,
UnsupportedContentType,
TypeNotFound,
MissingAttributes,
DeviceNotFound,
AttributeNotFound,
DuplicateDeviceId,
DuplicateGroup,
SecurityInformationMissing,
TokenRetrievalError,
AccessForbidden,
AuthenticationError,
BadConfiguration,
MissingHeaders,
MismatchedService,
WrongSyntax,
CommandNotFound,
MissingConfigParams,
NotificationError,
DeviceGroupNotFound,
GroupNotFound,
WrongExpressionType,
InvalidExpression,
BadAnswer,
BadTimestamp,
BadGeocoordinates
};
Loading