Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!method || !resource || !properties || !body) {
throw new ReferenceError('required parameter is missing');
}
/* Codes_SRS_NODE_DEVICE_AMQP_06_017: [The `sendTwinRequest` method shall throw an `ArgumentError` if the `method` argument is not a string.] */
/* Codes_SRS_NODE_DEVICE_AMQP_06_018: [The `sendTwinRequest` method shall throw an `ArgumentError` if the `resource` argument is not a string.] */
if (!this._isString(method) || !this._isString(resource)) {
throw new errors.ArgumentError('required string parameter is not a string');
}
/* Codes_SRS_NODE_DEVICE_AMQP_06_019: [The `sendTwinRequest` method shall throw an `ArgumentError` if the `properties` argument is not a an object.] */
if (!(properties instanceof Object)) {
throw new errors.ArgumentError('required properties parameter is not an object');
}
let amqpMessage = new AmqpMessage();
amqpMessage.messageAnnotations = {};
amqpMessage.properties = {};
//
// Amqp requires that the resource designation NOT be terminated by a slash. The agnostic twin client was terminating the
// resources with a slash which worked just dandy for MQTT.
//
// We need to cut off a terminating slash. If we cut off a terminating slash and the length of resource is zero then simply
// don't specify a resource.
//
// What if the caller specifies a "//" resource? Don't do that.
//
// So you'll note that in this case "/" sent down will be turned into an empty string. So why not
// simply send down "" to begin with? Because you can't send a falsy parameter.
//
/* Codes_SRS_NODE_DEVICE_AMQP_06_020: [The `method` argument shall be the value of the amqp message `operation` annotation.] */
queryOperationStatus: (request, correlationId, operationId, callback) => {
/*Codes_SRS_NODE_PROVISIONING_AMQP_16_015: [The `queryOperationStatus` method shall send a message on the pre-attached sender link with a `correlation_id` set to a newly generated UUID and the following application properties:
```
iotdps-operation-type: iotdps-get-operationstatus;
iotdps-operation-id: ;
```*/
let requestMessage = new AmqpMessage();
requestMessage.body = '';
requestMessage.application_properties = {};
requestMessage.application_properties[MessagePropertyNames.OperationType] = DeviceOperations.GetOperationStatus;
requestMessage.application_properties[MessagePropertyNames.OperationId] = operationId;
requestMessage.correlation_id = correlationId;
debug('registration status request: ' + JSON.stringify(requestMessage));
this._operations[requestMessage.correlation_id] = callback;
this._senderLink.send(requestMessage, (err) => {
if (err) {
delete this._operations[requestMessage.correlation_id];
const translatedError = translateError('query operation status failure', err);
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_006: [If the `queryOperationStatus` send request is rejected with an `InternalError` or `ThrottlingError`, the result.status value will be set with `assigning` and the callback will be invoked with *no* error object.] */
if ((translatedError instanceof errors.InternalServerError) || ((translatedError as AmqpTransportError) instanceof errors.ThrottlingError)) {
debug('retryable error on queryOperationStatus: ' + err.name);
let retryAfterInMilliseconds: number;