mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Fix Azure rest calls not working (#22854)
This commit is contained in:
@@ -29,7 +29,7 @@ import { HttpClient } from './httpClient';
|
|||||||
import { getProxyEnabledHttpClient, getTenantIgnoreList, updateTenantIgnoreList } from '../../utils';
|
import { getProxyEnabledHttpClient, getTenantIgnoreList, updateTenantIgnoreList } from '../../utils';
|
||||||
import { errorToPromptFailedResult } from './networkUtils';
|
import { errorToPromptFailedResult } from './networkUtils';
|
||||||
import { MsalCachePluginProvider } from '../utils/msalCachePlugin';
|
import { MsalCachePluginProvider } from '../utils/msalCachePlugin';
|
||||||
import { AzureListOperationResponse, ErrorResponseBodyWithError, isErrorResponseBody as isErrorResponseBodyWithError } from '../../azureResource/utils';
|
import { AzureListOperationResponse, ErrorResponseBodyWithError, isErrorResponseBodyWithError } from '../../azureResource/utils';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
export abstract class AzureAuth implements vscode.Disposable {
|
export abstract class AzureAuth implements vscode.Disposable {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
|
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
|
||||||
import { TokenCredentials } from '@azure/ms-rest-js';
|
import { TokenCredentials } from '@azure/ms-rest-js';
|
||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
import { AzureRestResponse, GetResourceGroupsResult, GetSubscriptionsResult, ResourceQueryResult, GetBlobContainersResult, GetFileSharesResult, HttpRequestMethod, GetLocationsResult, GetManagedDatabasesResult, CreateResourceGroupResult, GetBlobsResult, GetStorageAccountAccessKeyResult, AzureAccount, azureResource, AzureAccountProviderMetadata, AzureNetworkResponse, HttpClientResponse } from 'azurecore';
|
import { AzureRestResponse, GetResourceGroupsResult, GetSubscriptionsResult, ResourceQueryResult, GetBlobContainersResult, GetFileSharesResult, HttpRequestMethod, GetLocationsResult, GetManagedDatabasesResult, CreateResourceGroupResult, GetBlobsResult, GetStorageAccountAccessKeyResult, AzureAccount, azureResource, AzureAccountProviderMetadata, AzureNetworkResponse } from 'azurecore';
|
||||||
import { EOL } from 'os';
|
import { EOL } from 'os';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import { AppContext } from '../appContext';
|
import { AppContext } from '../appContext';
|
||||||
@@ -38,7 +38,7 @@ export type ErrorResponseBodyWithError = Required<ErrorResponseBody>;
|
|||||||
* @param body The body object to check
|
* @param body The body object to check
|
||||||
* @returns True if the body is an ErrorResponseBodyWithError
|
* @returns True if the body is an ErrorResponseBodyWithError
|
||||||
*/
|
*/
|
||||||
export function isErrorResponseBody(body: any): body is ErrorResponseBodyWithError {
|
export function isErrorResponseBodyWithError(body: any): body is ErrorResponseBodyWithError {
|
||||||
return 'error' in body && body.error;
|
return 'error' in body && body.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,21 +462,21 @@ export async function makeHttpRequest<B>(
|
|||||||
requestUrl = `${account.properties.providerSettings.settings.armResource.endpoint}${path}`;
|
requestUrl = `${account.properties.providerSettings.settings.armResource.endpoint}${path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: AzureNetworkResponse<HttpClientResponse<B>> | undefined = undefined;
|
let response: AzureNetworkResponse<B | ErrorResponseBodyWithError> | undefined = undefined;
|
||||||
switch (requestType) {
|
switch (requestType) {
|
||||||
case HttpRequestMethod.GET:
|
case HttpRequestMethod.GET:
|
||||||
response = await httpClient.sendGetRequestAsync<HttpClientResponse<B>>(requestUrl, {
|
response = await httpClient.sendGetRequestAsync<B | ErrorResponseBodyWithError>(requestUrl, {
|
||||||
headers: reqHeaders
|
headers: reqHeaders
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case HttpRequestMethod.POST:
|
case HttpRequestMethod.POST:
|
||||||
response = await httpClient.sendPostRequestAsync<HttpClientResponse<B>>(requestUrl, networkRequestOptions);
|
response = await httpClient.sendPostRequestAsync<B | ErrorResponseBodyWithError>(requestUrl, networkRequestOptions);
|
||||||
break;
|
break;
|
||||||
case HttpRequestMethod.PUT:
|
case HttpRequestMethod.PUT:
|
||||||
response = await httpClient.sendPutRequestAsync<HttpClientResponse<B>>(requestUrl, networkRequestOptions);
|
response = await httpClient.sendPutRequestAsync<B | ErrorResponseBodyWithError>(requestUrl, networkRequestOptions);
|
||||||
break;
|
break;
|
||||||
case HttpRequestMethod.DELETE:
|
case HttpRequestMethod.DELETE:
|
||||||
response = await httpClient.sendDeleteRequestAsync<HttpClientResponse<B>>(requestUrl, {
|
response = await httpClient.sendDeleteRequestAsync<B | ErrorResponseBodyWithError>(requestUrl, {
|
||||||
headers: reqHeaders
|
headers: reqHeaders
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -497,22 +497,18 @@ export async function makeHttpRequest<B>(
|
|||||||
} else if (response.status < 200 || response.status > 299) {
|
} else if (response.status < 200 || response.status > 299) {
|
||||||
let errorMessage: string[] = [];
|
let errorMessage: string[] = [];
|
||||||
errorMessage.push(response.status.toString());
|
errorMessage.push(response.status.toString());
|
||||||
if (response.data && response.data.error) {
|
const data = response.data;
|
||||||
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
|
if (isErrorResponseBodyWithError(data)) {
|
||||||
|
errorMessage.push(`${data.error.code} : ${data.error.message}`);
|
||||||
}
|
}
|
||||||
const error = new Error(errorMessage.join(EOL));
|
const error = new Error(errorMessage.join(EOL));
|
||||||
if (!ignoreErrors) {
|
if (!ignoreErrors) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
result.errors.push(error);
|
result.errors.push(error);
|
||||||
}
|
} else {
|
||||||
|
// We know this isn't an error response at this point
|
||||||
if (response) {
|
result.response = response as AzureNetworkResponse<B>;
|
||||||
result.response = {
|
|
||||||
headers: response.headers,
|
|
||||||
data: response.data.body,
|
|
||||||
status: response.status
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
7
extensions/azurecore/src/azurecore.d.ts
vendored
7
extensions/azurecore/src/azurecore.d.ts
vendored
@@ -287,13 +287,6 @@ declare module 'azurecore' {
|
|||||||
status: number;
|
status: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface HttpClientResponse<B> {
|
|
||||||
body: B;
|
|
||||||
headers: any;
|
|
||||||
status: Number;
|
|
||||||
error: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IExtension {
|
export interface IExtension {
|
||||||
/**
|
/**
|
||||||
* Gets the list of subscriptions for the specified AzureAccount
|
* Gets the list of subscriptions for the specified AzureAccount
|
||||||
|
|||||||
Reference in New Issue
Block a user