private async _populateSqlServerData()

in src/AzureSqlResourceManager.ts [110:149]


    private async _populateSqlServerData(serverName: string) {
        let sqlServerHostNameSuffix = this._authorizer.getCloudSuffixUrl('sqlServerHostname');
        if (serverName.endsWith(sqlServerHostNameSuffix)) {
            // remove the sqlServerHostname suffix from server url if it exists
            serverName = serverName.slice(0, serverName.lastIndexOf(sqlServerHostNameSuffix));
        }

        // https://docs.microsoft.com/rest/api/sql/2021-11-01/servers/list
        let httpRequest: WebRequest = {
            method: 'GET',
            uri: this._restClient.getRequestUri('//subscriptions/{subscriptionId}/providers/Microsoft.Sql/servers', {}, [], SqlApiVersion)
        }

        try {
            let httpResponse = await this._restClient.beginRequest(httpRequest);

            if (httpResponse.statusCode !== 200) {
                throw ToError(httpResponse);
            }

            let sqlServers = httpResponse.body && httpResponse.body.value as AzureSqlServer[];
            
            if (sqlServers && sqlServers.length > 0) {
                this._resource = sqlServers.filter((sqlResource) => sqlResource.name === serverName)[0];
                if (!this._resource) {
                    throw new Error(`Unable to get details of SQL server ${serverName}. Sql server '${serverName}' was not found in the subscription ${this._authorizer.subscriptionID}.`);
                }
            }
            else {
                throw new Error(`Unable to get details of SQL server ${serverName}. No SQL servers were found in the subscription ${this._authorizer.subscriptionID}.`);
            }
        }
        catch(error) {
            if (error instanceof AzureError) {
                throw new Error(JSON.stringify(error));
            }
            
            throw error;
        }
    }