mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
better error handling in base repo
This commit is contained in:
parent
9682abdded
commit
8b10ee0028
1 changed files with 14 additions and 7 deletions
|
@ -52,7 +52,7 @@ namespace Bit.App.Repositories
|
||||||
var errors = await ParseErrorsAsync(response).ConfigureAwait(false);
|
var errors = await ParseErrorsAsync(response).ConfigureAwait(false);
|
||||||
return ApiResult<T>.Failed(response.StatusCode, errors.ToArray());
|
return ApiResult<T>.Failed(response.StatusCode, errors.ToArray());
|
||||||
}
|
}
|
||||||
catch(JsonReaderException)
|
catch
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
return ApiResult<T>.Failed(response.StatusCode,
|
return ApiResult<T>.Failed(response.StatusCode,
|
||||||
|
@ -66,7 +66,7 @@ namespace Bit.App.Repositories
|
||||||
var errors = await ParseErrorsAsync(response).ConfigureAwait(false);
|
var errors = await ParseErrorsAsync(response).ConfigureAwait(false);
|
||||||
return ApiResult.Failed(response.StatusCode, errors.ToArray());
|
return ApiResult.Failed(response.StatusCode, errors.ToArray());
|
||||||
}
|
}
|
||||||
catch(JsonReaderException)
|
catch
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
return ApiResult.Failed(response.StatusCode,
|
return ApiResult.Failed(response.StatusCode,
|
||||||
|
@ -82,7 +82,9 @@ namespace Bit.App.Repositories
|
||||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
var errorResponseModel = JsonConvert.DeserializeObject<ErrorResponse>(responseContent);
|
var errorResponseModel = JsonConvert.DeserializeObject<ErrorResponse>(responseContent);
|
||||||
|
|
||||||
if(errorResponseModel.ValidationErrors.Count > 0)
|
if(errorResponseModel != null)
|
||||||
|
{
|
||||||
|
if((errorResponseModel.ValidationErrors?.Count ?? 0) > 0)
|
||||||
{
|
{
|
||||||
foreach(var valError in errorResponseModel.ValidationErrors)
|
foreach(var valError in errorResponseModel.ValidationErrors)
|
||||||
{
|
{
|
||||||
|
@ -97,6 +99,11 @@ namespace Bit.App.Repositories
|
||||||
errors.Add(new ApiError { Message = errorResponseModel.Message });
|
errors.Add(new ApiError { Message = errorResponseModel.Message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.Add(new ApiError { Message = "An unknown error has occured." });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue