Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getTranslatedError = function(err?: Error, message?: string): Error {
if (err instanceof errors.UnauthorizedError || err instanceof errors.NotConnectedError || err instanceof errors.DeviceNotFoundError) {
return err;
}
return translateError(message, err);
};
return function (err?: Error, result?: any): void {
if (err) {
done(translateError(errorMessage, err));
} else {
done(null, result);
}
};
};
this._senderLink.send(requestMessage, (err) => {
if (err) {
delete this._operations[requestMessage.correlation_id];
const translatedError = translateError('registration failure', err);
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_007: [If the `registrationRequest` send request is rejected with an `InternalError` or `ThrottlingError`, the result.status value will be set with `registering` 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 registration: ' + err.name);
let retryAfterInMilliseconds: number;
/*Codes_SRS_NODE_PROVISIONING_AMQP_06_009: [If the `registrationRequest` rejection error contains the info property`retry-after`, it will be interpreted as the number of seconds that should elapse before the next attempted operation. Otherwise default.] */
if ((err as any).info && (err as any).info[MessagePropertyNames.retryAfter]) {
retryAfterInMilliseconds = Number(((err as any).info[MessagePropertyNames.retryAfter] as string)) * 1000;
} else {
retryAfterInMilliseconds = this._config.pollingInterval;
}
callback(null, {status: 'registering'}, null, retryAfterInMilliseconds);
} else {
debug('non-retryable error on registration: ' + err.name);
/*Codes_SRS_NODE_PROVISIONING_AMQP_16_011: [The `registrationRequest` method shall call its callback with an error if the transport fails to send the request message.]*/
callback(err);
}
this._deviceMethodClient.detach((detachErr) => {
if (detachErr) {
debug('error detaching methods links: ' + detachErr.toString());
if (!finalError) {
finalError = translateError('error while detaching the methods links when disconnecting', detachErr);
}
} else {
debug('device methods links detached.');
}
callback();
});
}
this._stopC2DListener(err, (detachErr) => {
if (!finalError && detachErr) {
finalError = translateError('error while detaching the D2C link when disconnecting', detachErr);
}
callback();
});
} else {
this._amqp.connect(uri, this._config.x509, (err, connectResult) => {
if (err) {
this._fsm.transition('disconnected', connectCallback, translateError('AMQP Transport: Could not connect', err));
} else {
this._fsm.transition('authenticating', connectCallback, connectResult);
}
});
},