Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new Date(Date.now()).toString(),
new Date(totalAutoLockRenewDuration).toString(),
bMessage.messageId
);
this._clearMessageLockRenewTimer(bMessage.messageId as string);
}
};
// start
autoRenewLockTask();
}
try {
await this._onMessage(bMessage);
this._clearMessageLockRenewTimer(bMessage.messageId as string);
} catch (err) {
// This ensures we call users' error handler when users' message handler throws.
if (!isAmqpError(err)) {
log.error(
"[%s] An error occurred while running user's message handler for the message " +
"with id '%s' on the receiver '%s': %O",
connectionId,
bMessage.messageId,
this.name,
err
);
this._onError!(err);
}
// Do not want renewLock to happen unnecessarily, while abandoning the message. Hence,
// doing this here. Otherwise, this should be done in finally.
this._clearMessageLockRenewTimer(bMessage.messageId as string);
const error = translate(err);
// Nothing much to do if user's message handler throws. Let us try abandoning the message.
);
return;
}
resetTimerOnNewMessageReceived();
const bMessage: ServiceBusMessage = new ServiceBusMessage(
this._context,
context.message!,
context.delivery!,
true
);
try {
await this._onMessage(bMessage);
} catch (err) {
// This ensures we call users' error handler when users' message handler throws.
if (!isAmqpError(err)) {
log.error(
"[%s] An error occurred while running user's message handler for the message " +
"with id '%s' on the receiver '%s': %O",
connectionId,
bMessage.messageId,
this.name,
err
);
this._onError!(err);
}
const error = translate(err);
// Nothing much to do if user's message handler throws. Let us try abandoning the message.
if (
!bMessage.delivery.remote_settled &&
this.receiveMode === ReceiveMode.peekLock &&
);
return;
}
resetTimerOnNewMessageReceived();
const bMessage: ServiceBusMessage = new ServiceBusMessage(
this._context,
context.message!,
context.delivery!,
true
);
try {
await this._onMessage(bMessage);
} catch (err) {
// This ensures we call users' error handler when users' message handler throws.
if (!isAmqpError(err)) {
log.error(
"[%s] An error occurred while running user's message handler for the message " +
"with id '%s' on the receiver '%s': %O",
connectionId,
bMessage.messageId,
this.name,
err
);
this._onError!(err);
}
const error = translate(err);
// Nothing much to do if user's message handler throws. Let us try abandoning the message.
if (
!bMessage.delivery.remote_settled &&
this.receiveMode === ReceiveMode.peekLock &&
export function translate(err: AmqpError | Error): MessagingError {
if ((err as MessagingError).translated) {
// already translated
return err as MessagingError;
}
let error: MessagingError = err as MessagingError;
// Built-in errors like TypeError and RangeError should not be retryable as these indicate issues
// with user input and not an issue with the Messaging process.
if (err instanceof TypeError || err instanceof RangeError) {
error.retryable = false;
return error;
}
if (isAmqpError(err)) {
// translate
const condition = (err as AmqpError).condition;
const description = (err as AmqpError).description as string;
error = new MessagingError(description);
if ((err as any).stack) error.stack = (err as any).stack;
error.info = (err as AmqpError).info;
error.condition = condition;
if (condition) {
error.name = ConditionErrorNameMapper[condition as keyof typeof ConditionErrorNameMapper];
}
if (!error.name) error.name = "MessagingError";
if (
description &&
(description.includes("status-code: 404") ||
description.match(/The messaging entity .* could not be found.*/i) !== null)
) {
new Date(Date.now()).toString(),
new Date(totalAutoLockRenewDuration).toString(),
bMessage.messageId
);
this._clearMessageLockRenewTimer(bMessage.messageId as string);
}
};
// start
autoRenewLockTask();
}
try {
await this._onMessage(bMessage);
this._clearMessageLockRenewTimer(bMessage.messageId as string);
} catch (err) {
// This ensures we call users' error handler when users' message handler throws.
if (!isAmqpError(err)) {
log.error(
"[%s] An error occurred while running user's message handler for the message " +
"with id '%s' on the receiver '%s': %O",
connectionId,
bMessage.messageId,
this.name,
err
);
this._onError!(err);
}
// Do not want renewLock to happen unnecessarily, while abandoning the message. Hence,
// doing this here. Otherwise, this should be done in finally.
this._clearMessageLockRenewTimer(bMessage.messageId as string);
const error = translate(err);
// Nothing much to do if user's message handler throws. Let us try abandoning the message.