How to use the azure-iot-common.errors.NotConnectedError function in azure-iot-common

To help you get started, we’ve selected a few azure-iot-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-iot-sdk-node / common / transport / mqtt / src / mqtt_translate_error.ts View on Github external
export function translateError(mqttError: Error): MqttTransportError {
  let err: MqttTransportError;

  if (mqttError.message) {
    /* Codes_SRS_NODE_DEVICE_MQTT_ERRORS_18_002: [** `translateError` shall return a `NotConnectedError` if the MQTT error message contains the string 'client disconnecting' **]** */
    if (mqttError.message.indexOf('client disconnecting') > -1) {
      err = new errors.NotConnectedError('mqtt.js returned ' + mqttError.message + ' error');
    } else if (mqttError.message.indexOf('Invalid topic') > -1) {
      /* Codes_SRS_NODE_DEVICE_MQTT_ERRORS_18_003: [** `translateError` shall return a `FormatError` if the MQTT error message contains the string 'Invalid topic' **]** */
      err = new errors.FormatError('mqtt.js returned ' + mqttError.message + ' error');
    } else if (mqttError.message.indexOf('No connection to broker') > -1) {
      /* Codes_SRS_NODE_DEVICE_MQTT_ERRORS_18_004: [** `translateError` shall return a `NotConnectedError` if the MQTT error message contains the string 'No connection to broker' **]** */
      err = new errors.NotConnectedError('mqtt.js returned ' + mqttError.message + ' error');
    } else if (mqttError.message.indexOf('Unacceptable protocol version') > -1) {
      /* Codes_SRS_NODE_DEVICE_MQTT_ERRORS_18_005: [** `translateError` shall return a `NotImplementedError` if the MQTT error message contains the string 'Unacceptable protocol version' **]** */
      err = new errors.NotImplementedError('mqtt.js returned ' + mqttError.message + ' error');
    } else if (mqttError.message.indexOf('Identifier rejected') > -1) {
      /* Codes_SRS_NODE_DEVICE_MQTT_ERRORS_18_006: [** `translateError` shall return a `UnauthorizedError` if the MQTT error message contains the string 'Identifier rejected' **]** */
      err = new errors.UnauthorizedError('mqtt.js returned ' + mqttError.message + ' error');
    } else if (mqttError.message.indexOf('Server unavailable' ) > -1) {
      /* Codes_SRS_NODE_DEVICE_MQTT_ERRORS_18_007: [** `translateError` shall return a `ServiceUnavailableError` if the MQTT error message contains the string 'Server unavailable' **]** */
      err = new errors.ServiceUnavailableError('mqtt.js returned ' + mqttError.message + ' error');
    } else if (mqttError.message.indexOf('Bad username or password') > -1) {
github Azure / azure-iot-sdk-node / device / transport / mqtt / lib / mqtt_base.js View on Github external
var errCallback = function (error) {
      var err = error || new errors.NotConnectedError('Unable to establish a connection');
      self.client.removeListener('close', errCallback);
      self.client.removeListener('offline', errCallback);
      self.client.removeListener('disconnect', errCallback);
      self.client.removeListener('error', errCallback);
      done(err);
    };
github Azure / node-red-contrib-azure / iot-hub / node_modules / azure-iot-amqp-base / lib / amqp.js View on Github external
Amqp.prototype.send = function send(message, endpoint, to, done) {
  /*Codes_SRS_NODE_COMMON_AMQP_16_006: [The send method shall construct an AMQP message using information supplied by the caller, as follows:
  The ‘to’ field of the message should be set to the ‘to’ argument.
  The ‘body’ of the message should be built using the message argument.] */

  var amqpMessage = AmqpMessage.fromMessage(message);
  amqpMessage.properties.to = to;
  if (!this._connected) done(new errors.NotConnectedError('Cannot send while disconnected.'));

  var sendAction = function (sender, msg, done) {
    sender.send(msg)
      .then(function (state) {
        if (done) {
          var result = new results.MessageEnqueued(state);
          done(null, result);
        }
      })
      .catch(function (err) {
        /*Codes_SRS_NODE_IOTHUB_AMQPCOMMON_16_007: [If sendEvent encounters an error before it can send the request, it shall invoke the done callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
        if (done) done(err);
      });
  };

  if (!this._sender) {
github Azure / azure-iot-sdk-node / common / transport / amqp / lib / amqp.js View on Github external
.catch(function (err) {
        /*Codes_SRS_NODE_IOTHUB_AMQPCOMMON_16_007: [If sendEvent encounters an error before it can send the request, it shall invoke the `done` callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
        var error = new errors.NotConnectedError('AMQP: Could not create sender');
        error.amqpError = err;
        safeCallback(done, error);
      });
  }
github Azure / azure-iot-sdk-node / common / transport / amqp / lib / amqp.js View on Github external
.catch(function (err) {
        var error = new errors.NotConnectedError('AMQP: Could not create receiver');
        error.amqpError = err;
        /*Codes_SRS_NODE_COMMON_AMQP_16_021: [The `attachReceiverLink` method shall call the `done` callback with an `Error` object if the link object wasn't created successfully.]*/
        safeCallback(done, error);
      });
  }
github Azure / azure-iot-sdk-node / common / transport / amqp / lib / amqp.js View on Github external
Amqp.prototype.send = function send(message, endpoint, to, done) {
  if (!this._connected) {
    safeCallback(done, new errors.NotConnectedError('Cannot send while disconnected.'));
  } else {
    /*Codes_SRS_NODE_COMMON_AMQP_16_006: [The `send` method shall construct an AMQP message using information supplied by the caller, as follows:
    The ‘to’ field of the message should be set to the ‘to’ argument.
    The ‘body’ of the message should be built using the message argument.] */

    var amqpMessage = AmqpMessage.fromMessage(message);
    if (to !== undefined) {
      amqpMessage.properties.to = to;
    }

    var sendAction = function (sender, msg, done) {
      sender.send(msg)
        .then(function (state) {
          safeCallback(done, null, new results.MessageEnqueued(state));
          return null;
        })
github Azure / azure-iot-sdk-node / common / transport / amqp / src / amqp.ts View on Github external
          initializeCBS: (callback) => callback(new errors.NotConnectedError()),
          putToken: (audience, token, callback) => callback(new errors.NotConnectedError()),
github Azure / azure-iot-sdk-node / device / transport / amqp / src / amqp_device_method_client.ts View on Github external
          sendMethodResponse: (response, callback) => callback(new errors.NotConnectedError('Method Links were detached - the service already considers this method failed')),
          /*Codes_SRS_NODE_AMQP_DEVICE_METHOD_CLIENT_16_006: [The `onDeviceMethod` method shall save the `callback` argument so that it is called when the corresponding method call is received.]*/
github Azure / azure-iot-sdk-node / common / transport / amqp / src / amqp.ts View on Github external
disconnected: (context: EventContext) => {
            let callback = this._connectionCallback;
            this._connectionCallback = undefined;
            manageConnectionHandlers('removeListener');
            this._fsm.transition('disconnected', callback, new errors.NotConnectedError('rhea: connection disconnected'));
          },
          '*': () => this._fsm.deferUntilTransition()
github Azure / azure-iot-sdk-node / common / transport / amqp / lib / amqp.js View on Github external
Amqp.prototype.attachReceiverLink = function attachReceiverLink(endpoint, linkOptions, done) {
  /*Codes_SRS_NODE_COMMON_AMQP_16_017: [The `attachReceiverLink` method shall throw a ReferenceError if the `endpoint` argument is falsy.]*/
  if (!endpoint) {
    throw new ReferenceError('endpoint cannot be \'' + endpoint + '\'');
  }

  /*Codes_SRS_NODE_COMMON_AMQP_16_033: [The `attachReceiverLink` method shall call the `done` callback with a `NotConnectedError` object if the amqp client is not connected when the method is called.]*/
  if (!this._connected) {
    safeCallback(done, new errors.NotConnectedError('Cannot send while disconnected.'));
  } else {
    var self = this;
    var connectionError = null;
    var clientErrorHandler = function(err) {
      connectionError = err;
    };
    /*Codes_SRS_NODE_COMMON_AMQP_16_007: [If send encounters an error before it can send the request, it shall invoke the `done` callback function and pass the standard JavaScript Error object with a text description of the error (err.message).]*/
    this._amqp.on('client:errorReceived', clientErrorHandler);

    /*Codes_SRS_NODE_COMMON_AMQP_06_004: [The `attachReceiverLink` method shall create a policy object that contain link options to be merged if the linkOptions argument is not falsy.]*/
    /*Codes_SRS_NODE_COMMON_AMQP_16_018: [The `attachReceiverLink` method shall call `createReceiver` on the `amqp10` client object.]*/
    self._amqp.createReceiver(endpoint, linkOptions)
      .then(function (receiver) {
        self._amqp.removeListener('client:errorReceived', clientErrorHandler);
        if (!connectionError) {
          self._receivers[endpoint] = new AmqpReceiver(receiver);