1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-22 16:18:21 +01:00

Await async calls after loading. Added ConfigureAwaits throughout API repositories. Formatting.

This commit is contained in:
Kyle Spearrin 2016-08-16 19:20:41 -04:00
parent 83bcd39791
commit 2c05c9595b
16 changed files with 126 additions and 109 deletions

View File

@ -159,13 +159,15 @@ namespace Bit.App.Pages
{
if(string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.EmailAddress), AppResources.Ok);
return;
}
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.MasterPassword), AppResources.Ok);
return;
}
@ -180,9 +182,8 @@ namespace Bit.App.Pages
Device = new DeviceRequest(_appIdService, _deviceInfo)
};
var responseTask = _authService.TokenPostAsync(request);
_userDialogs.ShowLoading("Logging in...", MaskType.Black);
var response = await responseTask;
var response = await _authService.TokenPostAsync(request);
_userDialogs.HideLoading();
if(!response.Succeeded)
{

View File

@ -115,7 +115,8 @@ namespace Bit.App.Pages
{
if(string.IsNullOrWhiteSpace(CodeCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, "Verification code"), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
"Verification code"), AppResources.Ok);
return;
}
@ -126,9 +127,8 @@ namespace Bit.App.Pages
Device = new DeviceRequest(_appIdService, _deviceInfo)
};
var responseTask = _authService.TokenTwoFactorPostAsync(request);
_userDialogs.ShowLoading("Validating code...", MaskType.Black);
var response = await responseTask;
var response = await _authService.TokenTwoFactorPostAsync(request);
_userDialogs.HideLoading();
if(!response.Succeeded)
{

View File

@ -4,7 +4,6 @@ using Bit.App.Abstractions;
using Bit.App.Controls;
using Bit.App.Models.Api;
using Bit.App.Resources;
using Plugin.DeviceInfo.Abstractions;
using Xamarin.Forms;
using XLabs.Ioc;
using Acr.UserDialogs;
@ -106,7 +105,8 @@ namespace Bit.App.Pages
{
if(string.IsNullOrWhiteSpace(EmailCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.EmailAddress), AppResources.Ok);
return;
}
@ -115,9 +115,8 @@ namespace Bit.App.Pages
Email = EmailCell.Entry.Text
};
var responseTask = _accountApiRepository.PostPasswordHintAsync(request);
_userDialogs.ShowLoading("Submitting...", MaskType.Black);
var response = await responseTask;
var response = await _accountApiRepository.PostPasswordHintAsync(request);
_userDialogs.HideLoading();
if(!response.Succeeded)
{

View File

@ -48,11 +48,14 @@ namespace Bit.App.Pages
PasswordHintCell = new FormEntryCell("Master Password Hint (optional)", useLabelAsPlaceholder: true,
imageSource: "lightbulb", containerPadding: padding);
ConfirmPasswordCell = new FormEntryCell("Re-type Master Password", IsPassword: true,
nextElement: PasswordHintCell.Entry, useLabelAsPlaceholder: true, imageSource: "lock", containerPadding: padding);
nextElement: PasswordHintCell.Entry, useLabelAsPlaceholder: true, imageSource: "lock",
containerPadding: padding);
PasswordCell = new FormEntryCell(AppResources.MasterPassword, IsPassword: true,
nextElement: ConfirmPasswordCell.Entry, useLabelAsPlaceholder: true, imageSource: "lock", containerPadding: padding);
nextElement: ConfirmPasswordCell.Entry, useLabelAsPlaceholder: true, imageSource: "lock",
containerPadding: padding);
EmailCell = new FormEntryCell(AppResources.EmailAddress, nextElement: PasswordCell.Entry,
entryKeyboard: Keyboard.Email, useLabelAsPlaceholder: true, imageSource: "envelope", containerPadding: padding);
entryKeyboard: Keyboard.Email, useLabelAsPlaceholder: true, imageSource: "envelope",
containerPadding: padding);
PasswordHintCell.Entry.ReturnType = Enums.ReturnType.Done;
PasswordHintCell.Entry.Completed += Entry_Completed;
@ -178,16 +181,17 @@ namespace Bit.App.Pages
{
Email = normalizedEmail,
MasterPasswordHash = _cryptoService.HashPasswordBase64(key, PasswordCell.Entry.Text),
MasterPasswordHint = !string.IsNullOrWhiteSpace(PasswordHintCell.Entry.Text) ? PasswordHintCell.Entry.Text : null
MasterPasswordHint = !string.IsNullOrWhiteSpace(PasswordHintCell.Entry.Text)
? PasswordHintCell.Entry.Text : null
};
var responseTask = _accountsApiRepository.PostRegisterAsync(request);
_userDialogs.ShowLoading("Creating account...", MaskType.Black);
var response = await responseTask;
var response = await _accountsApiRepository.PostRegisterAsync(request);
_userDialogs.HideLoading();
if(!response.Succeeded)
{
await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message,
AppResources.Ok);
return;
}

View File

@ -62,7 +62,8 @@ namespace Bit.App.Pages
if(string.IsNullOrWhiteSpace(nameCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Name), AppResources.Ok);
return;
}
@ -71,21 +72,20 @@ namespace Bit.App.Pages
Name = nameCell.Entry.Text.Encrypt()
};
var saveTask = _folderService.SaveAsync(folder);
_userDialogs.ShowLoading("Saving...", MaskType.Black);
await saveTask;
var saveResult = await _folderService.SaveAsync(folder);
_userDialogs.HideLoading();
if(saveTask.Result.Succeeded)
if(saveResult.Succeeded)
{
await Navigation.PopModalAsync();
_userDialogs.Toast("New folder created.");
_googleAnalyticsService.TrackAppEvent("CreatedFolder");
}
else if(saveTask.Result.Errors.Count() > 0)
else if(saveResult.Errors.Count() > 0)
{
await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred);
await _userDialogs.AlertAsync(saveResult.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{

View File

@ -79,27 +79,27 @@ namespace Bit.App.Pages
if(string.IsNullOrWhiteSpace(nameCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Name), AppResources.Ok);
return;
}
folder.Name = nameCell.Entry.Text.Encrypt();
var saveTask = _folderService.SaveAsync(folder);
_userDialogs.ShowLoading("Saving...", MaskType.Black);
await saveTask;
var saveResult = await _folderService.SaveAsync(folder);
_userDialogs.HideLoading();
if(saveTask.Result.Succeeded)
if(saveResult.Succeeded)
{
await Navigation.PopModalAsync();
_userDialogs.Toast("Folder updated.");
_googleAnalyticsService.TrackAppEvent("EditedFolder");
}
else if(saveTask.Result.Errors.Count() > 0)
else if(saveResult.Errors.Count() > 0)
{
await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred);
await _userDialogs.AlertAsync(saveResult.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
@ -140,19 +140,19 @@ namespace Bit.App.Pages
return;
}
var deleteTask = _folderService.DeleteAsync(_folderId);
_userDialogs.ShowLoading("Deleting...", MaskType.Black);
await deleteTask;
var deleteTask = await _folderService.DeleteAsync(_folderId);
_userDialogs.HideLoading();
if((await deleteTask).Succeeded)
if(deleteTask.Succeeded)
{
await Navigation.PopModalAsync();
_userDialogs.Toast("Folder deleted.");
}
else if((await deleteTask).Errors.Count() > 0)
else if(deleteTask.Errors.Count() > 0)
{
await _userDialogs.AlertAsync((await deleteTask).Errors.First().Message, AppResources.AnErrorHasOccurred);
await _userDialogs.AlertAsync(deleteTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
@ -162,7 +162,8 @@ namespace Bit.App.Pages
private void AlertNoConnection()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage,
AppResources.Ok);
}
}
}

View File

@ -102,7 +102,8 @@ namespace Bit.App.Pages
public void AlertNoConnection()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage,
AppResources.Ok);
}
}
}

View File

@ -107,13 +107,15 @@ namespace Bit.App.Pages
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Password), AppResources.Ok);
return;
}
if(string.IsNullOrWhiteSpace(nameCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Name), AppResources.Ok);
return;
}
@ -132,20 +134,19 @@ namespace Bit.App.Pages
site.FolderId = folders.ElementAt(folderCell.Picker.SelectedIndex - 1).Id;
}
var saveTask = _siteService.SaveAsync(site);
_userDialogs.ShowLoading("Saving...", MaskType.Black);
await saveTask;
var saveTask = await _siteService.SaveAsync(site);
_userDialogs.HideLoading();
if(saveTask.Result.Succeeded)
if(saveTask.Succeeded)
{
await Navigation.PopModalAsync();
_userDialogs.Toast("New site created.");
_googleAnalyticsService.TrackAppEvent("CreatedSite");
}
else if(saveTask.Result.Errors.Count() > 0)
else if(saveTask.Errors.Count() > 0)
{
await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred);
await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
@ -183,7 +184,8 @@ namespace Bit.App.Pages
private void AlertNoConnection()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage,
AppResources.Ok);
}
}
}

View File

@ -140,13 +140,15 @@ namespace Bit.App.Pages
if(string.IsNullOrWhiteSpace(PasswordCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Password), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Password), AppResources.Ok);
return;
}
if(string.IsNullOrWhiteSpace(nameCell.Entry.Text))
{
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok);
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired,
AppResources.Name), AppResources.Ok);
return;
}
@ -166,21 +168,20 @@ namespace Bit.App.Pages
site.FolderId = null;
}
var saveTask = _siteService.SaveAsync(site);
_userDialogs.ShowLoading("Saving...", MaskType.Black);
await saveTask;
var saveTask = await _siteService.SaveAsync(site);
_userDialogs.HideLoading();
if(saveTask.Result.Succeeded)
if(saveTask.Succeeded)
{
await Navigation.PopModalAsync();
_userDialogs.Toast("Site updated.");
_googleAnalyticsService.TrackAppEvent("EditedSite");
}
else if(saveTask.Result.Errors.Count() > 0)
else if(saveTask.Errors.Count() > 0)
{
await _userDialogs.AlertAsync(saveTask.Result.Errors.First().Message, AppResources.AnErrorHasOccurred);
await _userDialogs.AlertAsync(saveTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
@ -209,7 +210,8 @@ namespace Bit.App.Pages
private async void GenerateCell_Tapped(object sender, EventArgs e)
{
if(!string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)
&& !await _userDialogs.ConfirmAsync("Are you sure you want to overwrite the current password?", null, AppResources.Yes, AppResources.No))
&& !await _userDialogs.ConfirmAsync("Are you sure you want to overwrite the current password?", null,
AppResources.Yes, AppResources.No))
{
return;
}
@ -235,20 +237,19 @@ namespace Bit.App.Pages
return;
}
var deleteTask = _siteService.DeleteAsync(_siteId);
_userDialogs.ShowLoading("Deleting...", MaskType.Black);
await deleteTask;
var deleteTask = await _siteService.DeleteAsync(_siteId);
_userDialogs.HideLoading();
if((await deleteTask).Succeeded)
if(deleteTask.Succeeded)
{
await Navigation.PopModalAsync();
_userDialogs.Toast("Site deleted.");
_googleAnalyticsService.TrackAppEvent("DeletedSite");
}
else if((await deleteTask).Errors.Count() > 0)
else if(deleteTask.Errors.Count() > 0)
{
await _userDialogs.AlertAsync((await deleteTask).Errors.First().Message, AppResources.AnErrorHasOccurred);
await _userDialogs.AlertAsync(deleteTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
}
else
{
@ -258,7 +259,8 @@ namespace Bit.App.Pages
private void AlertNoConnection()
{
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage,
AppResources.Ok);
}
}
}

View File

@ -33,10 +33,10 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
return await HandleErrorAsync(response).ConfigureAwait(false);
}
return ApiResult.Success(response.StatusCode);
@ -65,10 +65,10 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
return await HandleErrorAsync(response).ConfigureAwait(false);
}
return ApiResult.Success(response.StatusCode);

View File

@ -36,13 +36,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<TResponse>(response);
return await HandleErrorAsync<TResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<TResponse>(responseContent);
return ApiResult<TResponse>.Success(responseObj, response.StatusCode);
}
@ -70,13 +70,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<ListResponse<TResponse>>(response);
return await HandleErrorAsync<ListResponse<TResponse>>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<ListResponse<TResponse>>(responseContent);
return ApiResult<ListResponse<TResponse>>.Success(responseObj, response.StatusCode);
}
@ -104,13 +104,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<TResponse>(response);
return await HandleErrorAsync<TResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<TResponse>(responseContent);
return ApiResult<TResponse>.Success(responseObj, response.StatusCode);
}
@ -138,13 +138,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<TResponse>(response);
return await HandleErrorAsync<TResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<TResponse>(responseContent);
return ApiResult<TResponse>.Success(responseObj, response.StatusCode);
}
@ -172,10 +172,10 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
return await HandleErrorAsync(response).ConfigureAwait(false);
}
return ApiResult.Success(response.StatusCode);

View File

@ -34,13 +34,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<TokenResponse>(response);
return await HandleErrorAsync<TokenResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<TokenResponse>(responseContent);
return ApiResult<TokenResponse>.Success(responseObj, response.StatusCode);
}
@ -68,13 +68,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<TokenResponse>(response);
return await HandleErrorAsync<TokenResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<TokenResponse>(responseContent);
return ApiResult<TokenResponse>.Success(responseObj, response.StatusCode);
}

View File

@ -20,48 +20,54 @@ namespace Bit.App.Repositories
protected ApiResult HandledNotConnected()
{
return ApiResult.Failed(System.Net.HttpStatusCode.RequestTimeout, new ApiError { Message = "Not connected to the internet." });
return ApiResult.Failed(System.Net.HttpStatusCode.RequestTimeout,
new ApiError { Message = "Not connected to the internet." });
}
protected ApiResult<T> HandledNotConnected<T>()
{
return ApiResult<T>.Failed(System.Net.HttpStatusCode.RequestTimeout, new ApiError { Message = "Not connected to the internet." });
return ApiResult<T>.Failed(System.Net.HttpStatusCode.RequestTimeout,
new ApiError { Message = "Not connected to the internet." });
}
protected ApiResult HandledWebException()
{
return ApiResult.Failed(System.Net.HttpStatusCode.BadGateway, new ApiError { Message = "There is a problem connecting to the server." });
return ApiResult.Failed(System.Net.HttpStatusCode.BadGateway,
new ApiError { Message = "There is a problem connecting to the server." });
}
protected ApiResult<T> HandledWebException<T>()
{
return ApiResult<T>.Failed(System.Net.HttpStatusCode.BadGateway, new ApiError { Message = "There is a problem connecting to the server." });
return ApiResult<T>.Failed(System.Net.HttpStatusCode.BadGateway,
new ApiError { Message = "There is a problem connecting to the server." });
}
protected async Task<ApiResult<T>> HandleErrorAsync<T>(HttpResponseMessage response)
{
try
{
var errors = await ParseErrorsAsync(response);
var errors = await ParseErrorsAsync(response).ConfigureAwait(false);
return ApiResult<T>.Failed(response.StatusCode, errors.ToArray());
}
catch(JsonReaderException)
{ }
return ApiResult<T>.Failed(response.StatusCode, new ApiError { Message = "An unknown error has occured." });
return ApiResult<T>.Failed(response.StatusCode,
new ApiError { Message = "An unknown error has occured." });
}
protected async Task<ApiResult> HandleErrorAsync(HttpResponseMessage response)
{
try
{
var errors = await ParseErrorsAsync(response);
var errors = await ParseErrorsAsync(response).ConfigureAwait(false);
return ApiResult.Failed(response.StatusCode, errors.ToArray());
}
catch(JsonReaderException)
{ }
return ApiResult.Failed(response.StatusCode, new ApiError { Message = "An unknown error has occured." });
return ApiResult.Failed(response.StatusCode,
new ApiError { Message = "An unknown error has occured." });
}
private async Task<List<ApiError>> ParseErrorsAsync(HttpResponseMessage response)
@ -69,7 +75,7 @@ namespace Bit.App.Repositories
var errors = new List<ApiError>();
if(response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var errorResponseModel = JsonConvert.DeserializeObject<ErrorResponse>(responseContent);
foreach(var valError in errorResponseModel.ValidationErrors)

View File

@ -35,13 +35,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<CipherResponse>(response);
return await HandleErrorAsync<CipherResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<CipherResponse>(responseContent);
return ApiResult<CipherResponse>.Success(responseObj, response.StatusCode);
}
@ -69,13 +69,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<ListResponse<CipherResponse>>(response);
return await HandleErrorAsync<ListResponse<CipherResponse>>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<ListResponse<CipherResponse>>(responseContent);
return ApiResult<ListResponse<CipherResponse>>.Success(responseObj, response.StatusCode);
}
@ -103,13 +103,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<CipherHistoryResponse>(response);
return await HandleErrorAsync<CipherHistoryResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<CipherHistoryResponse>(responseContent);
return ApiResult<CipherHistoryResponse>.Success(responseObj, response.StatusCode);
}

View File

@ -34,10 +34,10 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
return await HandleErrorAsync(response).ConfigureAwait(false);
}
return ApiResult.Success(response.StatusCode);
@ -61,15 +61,16 @@ namespace Bit.App.Repositories
var requestMessage = new TokenHttpRequestMessage
{
Method = HttpMethod.Put,
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/identifier/", identifier, "/clear-token")),
RequestUri = new Uri(client.BaseAddress,
string.Concat(ApiRoute, "/identifier/", identifier, "/clear-token"))
};
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
return await HandleErrorAsync(response).ConfigureAwait(false);
}
return ApiResult.Success(response.StatusCode);

View File

@ -35,13 +35,13 @@ namespace Bit.App.Repositories
try
{
var response = await client.SendAsync(requestMessage);
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<ListResponse<FolderResponse>>(response);
return await HandleErrorAsync<ListResponse<FolderResponse>>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<ListResponse<FolderResponse>>(responseContent);
return ApiResult<ListResponse<FolderResponse>>.Success(responseObj, response.StatusCode);
}