diff --git a/sdk/eventhub/event-hubs/src/managementClient.ts b/sdk/eventhub/event-hubs/src/managementClient.ts index 8b85ab83bfc0..66cae060d583 100644 --- a/sdk/eventhub/event-hubs/src/managementClient.ts +++ b/sdk/eventhub/event-hubs/src/managementClient.ts @@ -318,84 +318,81 @@ export class ManagementClient extends LinkEntity { const sendOperationPromise = () => new Promise(async (resolve, reject) => { - try { - let count = 0; + let count = 0; - const retryTimeoutInMs = getRetryAttemptTimeoutInMs(options.retryOptions); - let timeTakenByInit = 0; + const retryTimeoutInMs = getRetryAttemptTimeoutInMs(options.retryOptions); + let timeTakenByInit = 0; - const rejectOnAbort = () => { - const requestName = options.requestName; - const desc: string = - `[${this._context.connectionId}] The request "${requestName}" ` + - `to has been cancelled by the user.`; - log.error(desc); - const error = new AbortError( - `The ${ - requestName ? requestName + " " : "" - }operation has been cancelled by the user.` - ); + const rejectOnAbort = () => { + const requestName = options.requestName; + const desc: string = + `[${this._context.connectionId}] The request "${requestName}" ` + + `to has been cancelled by the user.`; + log.error(desc); + const error = new AbortError( + `The ${requestName ? requestName + " " : ""}operation has been cancelled by the user.` + ); - reject(error); - }; + reject(error); + }; - if (aborter) { - if (aborter.aborted) { - return rejectOnAbort(); - } + if (aborter) { + if (aborter.aborted) { + return rejectOnAbort(); } + } - if (!this._isMgmtRequestResponseLinkOpen()) { - log.mgmt( - "[%s] Acquiring lock to get the management req res link.", - this._context.connectionId - ); - - const initOperationStartTime = Date.now(); + if (!this._isMgmtRequestResponseLinkOpen()) { + log.mgmt( + "[%s] Acquiring lock to get the management req res link.", + this._context.connectionId + ); - const actionAfterTimeout = () => { - const desc: string = `The request with message_id "${request.message_id}" timed out. Please try again later.`; - const e: Error = { - name: "OperationTimeoutError", - message: desc - }; + const initOperationStartTime = Date.now(); - return reject(translate(e)); + const actionAfterTimeout = () => { + const desc: string = `The request with message_id "${request.message_id}" timed out. Please try again later.`; + const e: Error = { + name: "OperationTimeoutError", + message: desc }; - const waitTimer = setTimeout(actionAfterTimeout, retryTimeoutInMs); + return reject(translate(e)); + }; + + const waitTimer = setTimeout(actionAfterTimeout, retryTimeoutInMs); - try { - await defaultLock.acquire(this.managementLock, () => { - return this._init(); - }); - } catch (err) { - return reject(translate(err)); - } finally { - clearTimeout(waitTimer); - } - timeTakenByInit = Date.now() - initOperationStartTime; + try { + await defaultLock.acquire(this.managementLock, () => { + return this._init(); + }); + } catch (err) { + return reject(translate(err)); + } finally { + clearTimeout(waitTimer); } + timeTakenByInit = Date.now() - initOperationStartTime; + } - const remainingOperationTimeoutInMs = retryTimeoutInMs - timeTakenByInit; + const remainingOperationTimeoutInMs = retryTimeoutInMs - timeTakenByInit; - const sendRequestOptions: SendRequestOptions = { - abortSignal: options.abortSignal, - requestName: options.requestName, - timeoutInSeconds: remainingOperationTimeoutInMs / 1000 - }; + const sendRequestOptions: SendRequestOptions = { + abortSignal: options.abortSignal, + requestName: options.requestName, + timeoutInSeconds: remainingOperationTimeoutInMs / 1000 + }; - count++; - if (count !== 1) { - // Generate a new message_id every time after the first attempt - request.message_id = generate_uuid(); - } else if (!request.message_id) { - // Set the message_id in the first attempt only if it is not set - request.message_id = generate_uuid(); - } + count++; + if (count !== 1) { + // Generate a new message_id every time after the first attempt + request.message_id = generate_uuid(); + } else if (!request.message_id) { + // Set the message_id in the first attempt only if it is not set + request.message_id = generate_uuid(); + } + try { const result = await this._mgmtReqResLink!.sendRequest(request, sendRequestOptions); - resolve(result); } catch (err) { err = translate(err);