How to use the azure-iot-common.errors.DeviceNotFoundError 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 / provisioning / device / src / provisioning_errors.ts View on Github external
export function translateError(message: string, status: number, result?: any, response?: any): ProvisioningError {
  let error: ProvisioningError;
  switch (status) {
    case 400:
      /*Codes_SRS_NODE_DPS_ERRORS_18_002: [`translateError` shall return an `ArgumentError` if the status code is `400`.]*/
      error = new errors.ArgumentError(message);
      break;
    case 401:
      /*Codes_SRS_NODE_DPS_ERRORS_18_003: [`translateError` shall return an `UnauthorizedError` if the status code is `401`.]*/
      error = new errors.UnauthorizedError(message);
      break;
    case 404:
      /*Codes_SRS_NODE_DPS_ERRORS_18_004: [`translateError` shall return an `DeviceNotFoundError` if the status code is `404`.]*/
      error = new errors.DeviceNotFoundError(message);
      break;
    case 429:
      /*Codes_SRS_NODE_DPS_ERRORS_18_005: [`translateError` shall return an `IotHubQuotaExceededError` if the status code is `429`.]*/
      error = new errors.IotHubQuotaExceededError(message);
      break;
    case 500:
      /*Codes_SRS_NODE_DPS_ERRORS_18_006: [`translateError` shall return an `InternalServerError` if the status code is `500`.]*/
      error = new errors.InternalServerError(message);
      break;
    default:
      /*Codes_SRS_NODE_DPS_ERRORS_18_007: [If the status code is unknown, `translateError` should return a generic Javascript `Error` object.]*/
      error = new Error(message);
      break;
  }

  /* Codes_SRS_NODE_DPS_ERRORS_18_008: [Any error object returned by `translateError` shall inherit from the generic `Error` Javascript object and have 3 properties:
github Azure / azure-iot-sdk-node / service / lib / amqp_simulated.js View on Github external
SimulatedAmqp.prototype.send = function send(deviceId, message, done) {
  if (done) {
    if (deviceId.search(/^no-device/) !== -1) {
      done(new errors.DeviceNotFoundError());
    }
    else {
      done(null, new results.MessageEnqueued());
      if (message.ack === 'full') {
        this._receiver.emit('message', {
          body: [{
            originalMessageId: message.messageId,
            deviceId: deviceId
          }]
        });
      }
    }
  }
};
github Azure / azure-iot-sdk-node / device / core / src / twin_errors.ts View on Github external
switch (status) {
    case 400:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_003: [`translateError` shall return an `ArgumentError` if the response status code is `400`.]*/
      error = new errors.ArgumentError();
      break;
    case 401:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_004: [`translateError` shall return an `UnauthorizedError` if the response status code is `401`.]*/
      error = new errors.UnauthorizedError();
      break;
    case 403:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_005: [`translateError` shall return an `IotHubQuotaExceededError` if the response status code is `403`.]*/
      error = new errors.IotHubQuotaExceededError();
      break;
    case 404:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_006: [`translateError` shall return an `DeviceNotFoundError` if the response status code is `404`.]*/
      error = new errors.DeviceNotFoundError();
      break;
    case 413:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_007: [`translateError` shall return an `MessageTooLargeError` if the response status code is `413`.]*/
      error = new errors.MessageTooLargeError();
      break;
    case 500:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_008: [`translateError` shall return an `InternalServerError` if the response status code is `500`.]*/
      error = new errors.InternalServerError();
      break;
    case 503:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_009: [`translateError` shall return an `ServiceUnavailableError` if the response status code is `503`.]*/
      error = new errors.ServiceUnavailableError();
      break;
    case 504:
      /*Codes_SRS_NODE_DEVICE_TWIN_ERRORS_18_011: [`translateError` shall return an `ServiceUnavailableError` if the response status code is `504`.]*/
      error = new errors.ServiceUnavailableError();
github Azure / azure-iot-sdks / node / service / lib / transport.js View on Github external
function translateError(err) {
  var error = err;

  if (err.constructor.name === 'AMQPError') {
    if (err.condition.contents === 'amqp:resource-limit-exceeded') {
      error = new errors.DeviceMaximumQueueDepthExceededError(err.description);
    }
    else if (err.condition.contents === 'amqp:not-found') {
      error = new errors.DeviceNotFoundError(err.description);
    }
    else if (err.condition.contents === 'amqp:unauthorized-access') {
      error = new errors.UnauthorizedError(err.description);
    }
    else {
      error = new Error(err.description);
    }
    error.transport = err;
  }
  else if (err instanceof amqp10.Errors.AuthenticationError) {
    error = new errors.UnauthorizedError(err.message);
  }

  return error;
}
github Azure / azure-iot-sdk-node / device / transport / http / src / http_errors.ts View on Github external
switch (response.statusCode) {
    case 400:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_003: [`translateError` shall return an `ArgumentError` if the HTTP response status code is `400`.]*/
      error = new errors.ArgumentError(message);
      break;
    case 401:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_004: [`translateError` shall return an `UnauthorizedError` if the HTTP response status code is `401`.]*/
      error = new errors.UnauthorizedError(message);
      break;
    case 403:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_005: [`translateError` shall return an `IotHubQuotaExceededError` if the HTTP response status code is `403`.]*/
      error = new errors.IotHubQuotaExceededError(message);
      break;
    case 404:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_006: [`translateError` shall return an `DeviceNotFoundError` if the HTTP response status code is `404`.]*/
      error = new errors.DeviceNotFoundError(message);
      break;
    case 413:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_007: [`translateError` shall return an `MessageTooLargeError` if the HTTP response status code is `413`.]*/
      error = new errors.MessageTooLargeError(message);
      break;
    case 500:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_008: [`translateError` shall return an `InternalServerError` if the HTTP response status code is `500`.]*/
      error = new errors.InternalServerError(message);
      break;
    case 503:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_009: [`translateError` shall return an `ServiceUnavailableError` if the HTTP response status code is `503`.]*/
      error = new errors.ServiceUnavailableError(message);
      break;
    default:
      /*Codes_SRS_NODE_DEVICE_HTTP_ERRORS_16_002: [If the HTTP error code is unknown, `translateError` should return a generic Javascript `Error` object.]*/
      error = new Error(message);
github Azure / azure-iot-sdk-node / common / transport / amqp / src / amqp_common_errors.ts View on Github external
| "com.microsoft:message-lock-lost"          | DeviceMessageLockLostError           |
  | "com.microsoft:precondition-failed"        | PreconditionFailedError              |
  | "com.microsoft:quota-exceeded"             | IotHubQuotaExceededError             |
  | "com.microsoft:timeout"                    | ServiceUnavailableError              |
  ]*/

  if ((amqpError as Amqp10Errors.ProtocolError).condition) {
    switch ((amqpError as Amqp10Errors.ProtocolError).condition) {
      case 'amqp:internal-error':
        error = new errors.InternalServerError(message);
        break;
      case 'amqp:link:message-size-exceeded':
        error = new errors.MessageTooLargeError(message);
        break;
      case 'amqp:not-found':
        error = new errors.DeviceNotFoundError(message);
        break;
      case 'amqp:not-implemented':
        error = new errors.NotImplementedError(message);
        break;
      case 'amqp:not-allowed':
        error = new errors.InvalidOperationError(message);
        break;
      case 'amqp:resource-limit-exceeded':
        error = new errors.IotHubQuotaExceededError(message);
        break;
      case 'amqp:unauthorized-access':
        error = new errors.UnauthorizedError(message);
        break;
      case 'com.microsoft:argument-error':
        error = new errors.ArgumentError(message);
        break;
github Azure / azure-iot-sdk-node / common / transport / http / src / rest_api_client.ts View on Github external
case 400:
        /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_014: [`translateError` shall return an `ArgumentError` if the HTTP response status code is `400`.]*/
        error = new errors.ArgumentError(message);
        break;
      case 401:
        /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_015: [`translateError` shall return an `UnauthorizedError` if the HTTP response status code is `401`.]*/
        error = new errors.UnauthorizedError(message);
        break;
      case 403:
        /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_016: [`translateError` shall return an `TooManyDevicesError` if the HTTP response status code is `403`.]*/
        error = new errors.TooManyDevicesError(message);
        break;
      case 404:
        if (errorContent && errorContent.code === 'DeviceNotFound') {
        /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_018: [`translateError` shall return an `DeviceNotFoundError` if the HTTP response status code is `404` and if the error code within the body of the error response is `DeviceNotFound`.]*/
          error = new errors.DeviceNotFoundError(message);
        } else if (errorContent && errorContent.code === 'IotHubNotFound') {
          /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_017: [`translateError` shall return an `IotHubNotFoundError` if the HTTP response status code is `404` and if the error code within the body of the error response is `IotHubNotFound`.]*/
          error = new errors.IotHubNotFoundError(message);
        } else {
          error = new Error('Not found');
        }
        break;
      case 408:
        /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_019: [`translateError` shall return a `DeviceTimeoutError` if the HTTP response status code is `408`.]*/
        error = new errors.DeviceTimeoutError(message);
        break;
      case 409:
        /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_020: [`translateError` shall return an `DeviceAlreadyExistsError` if the HTTP response status code is `409`.]*/
        error = new errors.DeviceAlreadyExistsError(message);
        break;
      case 412:
github Azure / node-red-contrib-azure / iot-hub / node_modules / azure-iot-amqp-base / lib / amqp_common_errors.js View on Github external
var translateError = function translateError(message, amqpError) {
  var error;

  if (amqpError.constructor.name === 'AMQPError') {
    switch (amqpError.condition.contents) {
      case 'amqp:not-found':
        /*Codes_SRS_NODE_DEVICE_AMQP_COMMON_ERRORS_16_006: [`translateError` shall return an `DeviceNotFoundError` if the AMQP error condition is `amqp:not-found`.]*/
        error = new errors.DeviceNotFoundError(message);
        break;
      case 'amqp:unauthorized-access':
        /*Codes_SRS_NODE_DEVICE_AMQP_COMMON_ERRORS_16_004: [`translateError` shall return an `UnauthorizedError` if the AMQP error condition is `amqp:unauthorized-access`.]*/
        error = new errors.UnauthorizedError(message);
        break;
      case 'amqp:internal-error':
        /*Codes_SRS_NODE_DEVICE_AMQP_COMMON_ERRORS_16_008: [`translateError` shall return an `InternalServerError` if the AMQP error condition is `amqp:internal-error`.]*/
        error = new errors.InternalServerError(message);
        break;
      case 'com.microsoft:timeout':
        /*Codes_SRS_NODE_DEVICE_AMQP_COMMON_ERRORS_16_009: [`translateError` shall return an `ServiceUnavailableError` if the AMQP error condition is `com.microsoft:timeout`.]*/
        error = new errors.ServiceUnavailableError(message);
        break;
      case 'amqp:link-message-size-exceeded':
        /*Codes_SRS_NODE_DEVICE_AMQP_COMMON_ERRORS_16_007: [`translateError` shall return an `MessageTooLargeError` if the AMQP error condition is `amqp:link-message-size-exceeded`.]*/
        error = new errors.MessageTooLargeError(message);