How to use the azure-iot-common.errors.ArgumentError 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 / device / transport / mqtt / src / mqtt.ts View on Github external
Object.keys(properties).forEach((key) => {
      /* Codes_SRS_NODE_DEVICE_MQTT_18_018: [** The `sendTwinRequest` method shall throw an `ArgumentError` if any members of the `properties` object fails to serialize to a string **]** */
      if (!util.isString(properties[key]) && !util.isNumber(properties[key]) && !util.isBoolean(properties[key])) {
        throw new errors.ArgumentError('required properties object has non-string properties');
      }

      /* Codes_SRS_NODE_DEVICE_MQTT_18_023: [** Each member of the `properties` object shall add another 'name=value&' pair to the `propertyQuery` string. **]**   */
      propString += (propString === '') ? '?' : '&';
      propString += key + '=' + properties[key];
    });
github Azure / azure-iot-sdk-node / provisioning / device / src / client.ts View on Github external
} else if (isTpmSecurity) {
      if (isTpmTransport) {
        /* Codes_SRS_PROVISIONING_CLIENT_18_003: [ If `securityClient` implements `TPMSecurityClient` and the `transport` supports TPM authentication, then `create` shall return a `TpmRegistration` object. ] */
        return new TpmRegistration(provisioningHost, idScope, transport as TpmProvisioningTransport, securityClient as TpmSecurityClient);
      } else {
        /* Codes_SRS_PROVISIONING_CLIENT_18_004: [ If `securityClient` implements `TPMSecurityClient` and the `transport` dos not implement `TPMProvisioningTransport`, then `create` shall throw an `ArgumentError` exception. ] */
        throw new errors.ArgumentError('Transport does not support TPM authentication');
      }
    } else if (isSymmetricKeySecurity) {
      if (isSymmetricKeyTransport) {
        /* Codes_SRS_PROVISIONING_CLIENT_06_003: [If `securityClient` implements `SymmetricKeySecurityClient` and the `transport` implements `SymmetricKeyProvisioningTransport`, then `create` shall return an `SymmetricKeyRegistration` object.] */
        return new SymmetricKeyRegistration(provisioningHost, idScope, transport as SymmetricKeyProvisioningTransport, securityClient as SymmetricKeySecurityClient);

      } else {
        /* Codes_SRS_PROVISIONING_CLIENT_06_004: [If `securityClient` implements `SymmetricKeySecurityClient` and the `transport` does not implement `SymmetricKeyProvisioningTransport`, then `create` shall throw an `ArgumentError` exception.] */
        throw new errors.ArgumentError('Transport does not support SymmetricKey authentication');
      }
    } else {
      /* Codes_SRS_PROVISIONING_CLIENT_18_005: [ If `securityClient` does not implement `X509SecurityClient`, `TPMSecurityClient`,  or `SymmetricKeySecurityClient` then `create` shall show an `ArgumentError` exception. ] */
      throw new errors.ArgumentError('Invalid security object');
    }
  }
}
github Azure / azure-iot-sdk-node / provisioning / device / src / client.ts View on Github external
if (isX509Security) {
      if (isX509Transport) {
        /* Codes_SRS_PROVISIONING_CLIENT_18_001: [ If `securityClient` implements `X509SecurityClient` and the `transport` implements `X509ProvisioningTransport`, then `create` shall return an `X509Registration` object. ] */
        return new X509Registration(provisioningHost, idScope, transport as X509ProvisioningTransport, securityClient as X509SecurityClient);
      } else {
        /* Codes_SRS_PROVISIONING_CLIENT_18_002: [ If `securityClient` implements `X509SecurityClient` and the `transport` does not implement `X509ProvisioningTransport`, then `create` shall throw an `ArgumentError` exception. ] */
        throw new errors.ArgumentError('Transport does not support X509 authentication');
      }
    } else if (isTpmSecurity) {
      if (isTpmTransport) {
        /* Codes_SRS_PROVISIONING_CLIENT_18_003: [ If `securityClient` implements `TPMSecurityClient` and the `transport` supports TPM authentication, then `create` shall return a `TpmRegistration` object. ] */
        return new TpmRegistration(provisioningHost, idScope, transport as TpmProvisioningTransport, securityClient as TpmSecurityClient);
      } else {
        /* Codes_SRS_PROVISIONING_CLIENT_18_004: [ If `securityClient` implements `TPMSecurityClient` and the `transport` dos not implement `TPMProvisioningTransport`, then `create` shall throw an `ArgumentError` exception. ] */
        throw new errors.ArgumentError('Transport does not support TPM authentication');
      }
    } else if (isSymmetricKeySecurity) {
      if (isSymmetricKeyTransport) {
        /* Codes_SRS_PROVISIONING_CLIENT_06_003: [If `securityClient` implements `SymmetricKeySecurityClient` and the `transport` implements `SymmetricKeyProvisioningTransport`, then `create` shall return an `SymmetricKeyRegistration` object.] */
        return new SymmetricKeyRegistration(provisioningHost, idScope, transport as SymmetricKeyProvisioningTransport, securityClient as SymmetricKeySecurityClient);

      } else {
        /* Codes_SRS_PROVISIONING_CLIENT_06_004: [If `securityClient` implements `SymmetricKeySecurityClient` and the `transport` does not implement `SymmetricKeyProvisioningTransport`, then `create` shall throw an `ArgumentError` exception.] */
        throw new errors.ArgumentError('Transport does not support SymmetricKey authentication');
      }
    } else {
      /* Codes_SRS_PROVISIONING_CLIENT_18_005: [ If `securityClient` does not implement `X509SecurityClient`, `TPMSecurityClient`,  or `SymmetricKeySecurityClient` then `create` shall show an `ArgumentError` exception. ] */
      throw new errors.ArgumentError('Invalid security object');
    }
  }
}
github Azure / azure-iot-sdk-node / device / transport / mqtt / src / mqtt.ts View on Github external
/* Codes_SRS_NODE_DEVICE_MQTT_18_019: [** The `sendTwinRequest` method shall throw an `ReferenceError` if the `resource` argument is falsy. **]** */
    /* Codes_SRS_NODE_DEVICE_MQTT_18_011: [** The `sendTwinRequest` method shall throw an `ReferenceError` if the `properties` argument is falsy. **]** */
    /* Codes_SRS_NODE_DEVICE_MQTT_18_013: [** The `sendTwinRequest` method shall throw an `ReferenceError` if the `body` argument is falsy. **]** */
    if (!method || !resource || !properties ||  !body) {
      throw new ReferenceError('required parameter is missing');
    }

    /* Codes_SRS_NODE_DEVICE_MQTT_18_010: [** The `sendTwinRequest` method shall throw an `ArgumentError` if the `method` argument is not a string. **]** */
    /* Codes_SRS_NODE_DEVICE_MQTT_18_020: [** The `sendTwinRequest` method shall throw an `ArgumentError` if the `resource` argument is not a string. **]** */
    if (!util.isString(method) || !util.isString(resource)) {
      throw new errors.ArgumentError('required string parameter is not a string');
    }

    /* Codes_SRS_NODE_DEVICE_MQTT_18_012: [** The `sendTwinRequest` method shall throw an `ArgumentError` if the `properties` argument is not a an object. **]** */
    if (!util.isObject(properties)) {
      throw new errors.ArgumentError('required properties parameter is not an object');
    }

    /* Codes_SRS_NODE_DEVICE_MQTT_18_022: [** The `propertyQuery` string shall be construced from the `properties` object. **]**   */
    let propString = '';
    Object.keys(properties).forEach((key) => {
      /* Codes_SRS_NODE_DEVICE_MQTT_18_018: [** The `sendTwinRequest` method shall throw an `ArgumentError` if any members of the `properties` object fails to serialize to a string **]** */
      if (!util.isString(properties[key]) && !util.isNumber(properties[key]) && !util.isBoolean(properties[key])) {
        throw new errors.ArgumentError('required properties object has non-string properties');
      }

      /* Codes_SRS_NODE_DEVICE_MQTT_18_023: [** Each member of the `properties` object shall add another 'name=value&' pair to the `propertyQuery` string. **]**   */
      propString += (propString === '') ? '?' : '&';
      propString += key + '=' + properties[key];
    });

    /* Codes_SRS_NODE_DEVICE_MQTT_18_021: [** The topic name passed to the publish method shall be $iothub/twin/`method`/`resource`/?`propertyQuery` **]** */
github Azure / azure-iot-sdk-node / common / transport / http / src / rest_api_client.ts View on Github external
constructor(config: RestApiClient.TransportConfig, userAgent: string, httpRequestBuilder?: HttpBase) {
    /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_001: [The `RestApiClient` constructor shall throw a `ReferenceError` if config is falsy.]*/
    if (!config) throw new ReferenceError('config cannot be \'' + config + '\'');
    /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_002: [The `RestApiClient` constructor shall throw an `ArgumentError` if config is missing a `host` property.]*/
    if (!config.host) throw new errors.ArgumentError('config.host cannot be \'' + config.host + '\'');
    /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_18_001: [The `RestApiClient` constructor shall throw a `ReferenceError` if `userAgent` is falsy.]*/
    if (!userAgent) throw new ReferenceError('userAgent cannot be \'' + userAgent + '\'');

    this._config = config;
    this._userAgent = userAgent;

    /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_003: [The `RestApiClient` constructor shall use `azure-iot-common.Http` as the internal HTTP client if the `httpBase` argument is `undefined`.]*/
    /*Codes_SRS_NODE_IOTHUB_REST_API_CLIENT_16_004: [The `RestApiClient` constructor shall use the value of the `httpBase` argument as the internal HTTP client if present.]*/
    this._http = httpRequestBuilder || new HttpBase();
  }
github Azure / azure-iot-sdk-node / common / transport / amqp / src / amqp_common_errors.ts View on Github external
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;
      case 'com.microsoft:argument-out-of-range':
        error = new errors.ArgumentOutOfRangeError(message);
        break;
      case 'com.microsoft:device-already-exists':
        error = new errors.DeviceAlreadyExistsError(message);
        break;
      case 'com.microsoft:device-container-throttled':
        error = new errors.ThrottlingError(message);
        break;
      case 'com.microsoft:iot-hub-suspended':
        error = new errors.IoTHubSuspendedError(message);
        break;
      case 'com.microsoft:message-lock-lost':
        error = new errors.DeviceMessageLockLostError(message);
        break;
github Azure / azure-iot-sdk-node / device / core / src / connection_string.ts View on Github external
export function parse(source: string): ConnectionString {
  /*Codes_SRS_NODE_DEVICE_CONNSTR_05_001: [The parse method shall return the result of calling azure-iot-common.ConnectionString.parse.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_05_002: [It shall throw ArgumentError if any of 'HostName' or 'DeviceId' fields are not found in the source argument.]*/
  const connectionString = ConnectionString.parse(source, ['HostName', 'DeviceId']);
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_001: [It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_006: [It shall throw `ArgumentError` if `SharedAccessKey` and `SharedAccessSignature` are present at the same time.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_007: [It shall throw `ArgumentError` if `SharedAccessSignature` and `x509` are present at the same time.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_008: [It shall throw `ArgumentError` if none of `SharedAccessKey`, `SharedAccessSignature` and `x509` are present.]*/
  if (connectionString.SharedAccessKey && connectionString.x509) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey or x509=true');
  } else if (connectionString.SharedAccessKey && connectionString.SharedAccessSignature) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey or SharedAccessSignature');
  } else if (connectionString.SharedAccessSignature && connectionString.x509) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessSignature or x509=true');
  } else if ((!connectionString.SharedAccessKey && !connectionString.SharedAccessSignature && !connectionString.x509)) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey, SharedAccessSignature or x509=true');
  }

  return connectionString;
}
github Azure / azure-iot-sdk-node / device / core / src / connection_string.ts View on Github external
export function parse(source: string): ConnectionString {
  /*Codes_SRS_NODE_DEVICE_CONNSTR_05_001: [The parse method shall return the result of calling azure-iot-common.ConnectionString.parse.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_05_002: [It shall throw ArgumentError if any of 'HostName' or 'DeviceId' fields are not found in the source argument.]*/
  const connectionString = ConnectionString.parse(source, ['HostName', 'DeviceId']);
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_001: [It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_006: [It shall throw `ArgumentError` if `SharedAccessKey` and `SharedAccessSignature` are present at the same time.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_007: [It shall throw `ArgumentError` if `SharedAccessSignature` and `x509` are present at the same time.]*/
  /*Codes_SRS_NODE_DEVICE_CONNSTR_16_008: [It shall throw `ArgumentError` if none of `SharedAccessKey`, `SharedAccessSignature` and `x509` are present.]*/
  if (connectionString.SharedAccessKey && connectionString.x509) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey or x509=true');
  } else if (connectionString.SharedAccessKey && connectionString.SharedAccessSignature) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey or SharedAccessSignature');
  } else if (connectionString.SharedAccessSignature && connectionString.x509) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessSignature or x509=true');
  } else if ((!connectionString.SharedAccessKey && !connectionString.SharedAccessSignature && !connectionString.x509)) {
    throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey, SharedAccessSignature or x509=true');
  }

  return connectionString;
}
github Azure / azure-iot-sdk-node / device / core / src / twin_errors.ts View on Github external
export function translateError(response: any, status: number): TwinBaseError {
  let error: TwinBaseError;
  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();
github Azure / azure-iot-sdk-node / device / transport / amqp / src / amqp_device_method_client.ts View on Github external
sendMethodResponse(response: DeviceMethodResponse, callback?: (err?: Error, result?: any) => void): void {
    if (!response) throw new ReferenceError('response cannot be \'' + response + '\'');
    if (response.status === null || response.status === undefined) throw new errors.ArgumentError('response.status cannot be \'' + response.status + '\'');
    if (!response.requestId) throw new errors.ArgumentError('response.requestId cannot be \'' + response.requestId + '\'');

    this._fsm.handle('sendMethodResponse', response, callback);
  }