From 923272f9893f0cd470ad3829a96c666d87938d5e Mon Sep 17 00:00:00 2001 From: Amir Omidi Date: Mon, 11 May 2020 13:02:28 -0700 Subject: [PATCH] Let's log every potential failure (#10342) * Let's log every potential failure * Add more context to the error --- .../src/account-provider/auths/azureAuth.ts | 44 ++++++++++++------- .../account-provider/auths/azureDeviceCode.ts | 1 + 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/extensions/azurecore/src/account-provider/auths/azureAuth.ts b/extensions/azurecore/src/account-provider/auths/azureAuth.ts index a26086e9d5..bcb8aa0ecb 100644 --- a/extensions/azurecore/src/account-provider/auths/azureAuth.ts +++ b/extensions/azurecore/src/account-provider/auths/azureAuth.ts @@ -225,7 +225,6 @@ export abstract class AzureAuth implements vscode.Disposable { } catch (ex) { console.log(`Could not refresh access token for ${JSON.stringify(tenant)} - silently removing the tenant from the user's account.`); azureAccount.properties.tenants = azureAccount.properties.tenants.filter(t => t.id !== tenant.id); - console.log(ex, ex?.data, ex?.response); continue; } @@ -272,28 +271,40 @@ export abstract class AzureAuth implements vscode.Disposable { } protected async makePostRequest(uri: string, postData: { [key: string]: string }, validateStatus = false) { - const config: AxiosRequestConfig = { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' + try { + const config: AxiosRequestConfig = { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + }; + + if (validateStatus) { + config.validateStatus = () => true; } - }; - if (validateStatus) { - config.validateStatus = () => true; + return await axios.post(uri, qs.stringify(postData), config); + } catch (ex) { + console.log('Unexpected error making Azure auth request', 'azureCore.postRequest', JSON.stringify(ex?.response?.data, undefined, 2)); + throw ex; } - - return axios.post(uri, qs.stringify(postData), config); } protected async makeGetRequest(token: string, uri: string): Promise> { - const config = { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json', - }, - }; + try { + const config = { + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }; - return axios.get(uri, config); + return await axios.get(uri, config); + } catch (ex) { + // Intercept and print error + console.log('Unexpected error making Azure auth request', 'azureCore.getRequest', JSON.stringify(ex?.response?.data, undefined, 2)); + // rethrow error + throw ex; + } } protected async getTenants(token: AccessToken): Promise { @@ -325,7 +336,6 @@ export abstract class AzureAuth implements vscode.Disposable { return tenants; } catch (ex) { console.log(ex); - console.log(JSON.stringify(ex?.response?.data, undefined, 2)); throw new Error('Error retreiving tenant information'); } } diff --git a/extensions/azurecore/src/account-provider/auths/azureDeviceCode.ts b/extensions/azurecore/src/account-provider/auths/azureDeviceCode.ts index 8ab6d77d34..ce434674a9 100644 --- a/extensions/azurecore/src/account-provider/auths/azureDeviceCode.ts +++ b/extensions/azurecore/src/account-provider/auths/azureDeviceCode.ts @@ -150,6 +150,7 @@ export class AzureDeviceCode extends AzureAuth { return result; } catch (ex) { console.log(ex); + console.log('Unexpected error making Azure auth request', 'azureCore.checkForResult', JSON.stringify(ex?.response?.data, undefined, 2)); throw new Error(msg); } }