How to use the azure-iot-provisioning-device.translateError function in azure-iot-provisioning-device

To help you get started, we’ve selected a few azure-iot-provisioning-device 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 / transport / http / src / http.ts View on Github external
debug(JSON.stringify(response.headers));
        /* Codes_SRS_NODE_PROVISIONING_HTTP_06_010: [If the `queryOperationStatus` response contains the `header` `retry-after`, it will be interpreted as the number of seconds that should elapse before the next attempt at the `queryOperationStatus` operation.] */
        let retryAfterInMilliseconds: number = this._config.pollingInterval;
        if (response.headers && response.headers[_retryAfterPropertyName]) {
          retryAfterInMilliseconds = Number(response.headers[_retryAfterPropertyName]) * 1000;
        }
        if (response.statusCode < 300) {
          /* Codes_SRS_NODE_PROVISIONING_HTTP_18_039: [ If the Http request succeeds, `queryOperationStatus` shall call `callback`, passing a `null` error along with the `result` and `response` objects. ] */
          callback(null, result, response, retryAfterInMilliseconds);
        } else if (response.statusCode >= 429) {
          /* Codes_SRS_NODE_PROVISIONING_HTTP_06_009: [If the `queryOperationStatus` response contains a status code >= 429, the result.status value will be set with `assigning` and the callback will be invoked with *no* error object.]*/
          callback(null, {status: 'assigning', operationId: operationId}, response, retryAfterInMilliseconds);
        } else {
          /* Codes_SRS_NODE_PROVISIONING_HTTP_18_026: [ If the Http response has a failed status code, `queryOperationStatus` shall use `translateError` to translate this to a common error object ] */
          /* Codes_SRS_NODE_PROVISIONING_HTTP_18_038: [ If the Http request fails for any reason, `queryOperationStatus` shall call `callback`, passing the error along with the `result` and `response` objects. ] */
          callback(translateError('GET operation returned failure', response.statusCode, result, response));
        }
      }
    });
  }
github Azure / azure-iot-sdk-node / provisioning / transport / http / src / http.ts View on Github external
debug(JSON.stringify(response.headers));
        let retryAfterInMilliseconds: number = this._config.pollingInterval;
        /*Codes_SRS_NODE_PROVISIONING_HTTP_06_011: [ If the `registrationRequest` response contains the `header` `retry-after`, it will be interpreted as the number of seconds that should elapse before the next attempted operation.] */
        if (response.headers && response.headers[_retryAfterPropertyName]) {
          retryAfterInMilliseconds = Number(response.headers[_retryAfterPropertyName]) * 1000;
        }
        if (response.statusCode < 300) {
          /* Codes_SRS_NODE_PROVISIONING_HTTP_18_045: [ If the Http request succeeds, `registrationRequest` shall call `callback`, passing a `null` error along with the `result` and `response` objects. ] */
          callback(null, result, response, retryAfterInMilliseconds);
        } else if (response.statusCode >= 429) {
          /*Codes_SRS_NODE_PROVISIONING_HTTP_06_012: [ If the `registrationRequest` response contains a status code >= 429, the result.status value will be set with `registering` and the callback will be invoked with *no* error object.] */
          callback(null, {status: 'registering'} as any, response, retryAfterInMilliseconds);
        } else {
          /* Codes_SRS_NODE_PROVISIONING_HTTP_18_014: [ If the Http response has a failed status code, `registrationRequest` shall use `translateError` to translate this to a common error object ] */
          /* Codes_SRS_NODE_PROVISIONING_HTTP_18_044: [ If the Http request fails for any reason, `registrationRequest` shall call `callback`, passing the error along with the `result` and `response` objects. ] */
          callback(translateError('PUT operation returned failure', response.statusCode, result, response));
        }
      }
    });
  }
github Azure / azure-iot-sdk-node / provisioning / transport / mqtt / src / mqtt.ts View on Github external
}
            delete this._operations[rid];
            if (status < 300) {
              /* Codes_SRS_NODE_PROVISIONING_MQTT_18_013: [ When `registrationRequest` receives a successful response from the service, it shall call `callback` passing in null and the response.] */
              /* Codes_SRS_NODE_PROVISIONING_MQTT_18_027: [ When `queryOperationStatus` receives a successful response from the service, it shall call `callback` passing in null and the response.] */
              handler(null, payloadJson, retryAfterInMilliseconds);
            } else if (status >= 429) {
              /*Codes_SRS_NODE_PROVISIONING_MQTT_06_003: [ When `registrationRequest` receives a response with status >429, it shall invoke `callback` with a result object containing property `status` with a value `registering` and no `operationId` property.] */
              /*Codes_SRS_NODE_PROVISIONING_MQTT_06_004: [ When `queryOperationStatus` receives a response with status >429, it shall invoke `callback` with a result object containing property `status` with a value `assigning` and `operationId` property with value of the passed to the request.] */
              handler(null, {status: statusString, operationId: operationId}, retryAfterInMilliseconds);
            } else {
              /* Codes_SRS_NODE_PROVISIONING_MQTT_18_012: [ If `registrationRequest` receives a response with status >= 300 and <429, it shall consider the request failed and create an error using `translateError`.] */
              /* Codes_SRS_NODE_PROVISIONING_MQTT_18_015: [ When `registrationRequest` receives an error from the service, it shall call `callback` passing in the error.] */
              /* Codes_SRS_NODE_PROVISIONING_MQTT_18_026: [ If `queryOperationStatus` receives a response with status >= 300 and <429, it shall consider the query failed and create an error using `translateError`.] */
              /* Codes_SRS_NODE_PROVISIONING_MQTT_18_029: [ When `queryOperationStatus` receives an error from the service, it shall call `callback` passing in the error.] */
              handler(translateError('incoming message failure', status, payloadJson, { topic: topic, payload: payloadJson }));
            }
          } else {
            debug('received an unknown request id: ' + rid + ' topic: ' + topic);
          }
        } else {
          debug('received message with no request id. Topic is: ' + topic);
        }
      } else {
        debug('received a topic string with insufficient content: ' + topic);
      }
    };