mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-26 16:57:59 +01:00
[EC-469] Improve ApiException message (#2288)
* EC-469 Improve ApiException message to have the validation errors and message provided by the ErrorResponse * EC-469 Updated default message format for ErrorResponse GetFullMessage()
This commit is contained in:
parent
f772ee7068
commit
4f4953206e
@ -16,5 +16,7 @@ namespace Bit.Core.Exceptions
|
||||
}
|
||||
|
||||
public ErrorResponse Error { get; set; }
|
||||
|
||||
public override string Message => Error?.GetFullMessage() ?? base.Message;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Response
|
||||
@ -67,6 +68,32 @@ namespace Bit.Core.Models.Response
|
||||
return Message;
|
||||
}
|
||||
|
||||
public string GetFullMessage()
|
||||
{
|
||||
string GetDefaultMessage() => $"{(int)StatusCode} {StatusCode}. {Message}";
|
||||
|
||||
if (ValidationErrors is null)
|
||||
{
|
||||
return GetDefaultMessage();
|
||||
}
|
||||
|
||||
var valErrors = ValidationErrors.Where(e => e.Value != null && e.Value.Any()).ToList();
|
||||
if (!valErrors.Any())
|
||||
{
|
||||
return GetDefaultMessage();
|
||||
}
|
||||
|
||||
string GetFullError(string key, List<string> errors)
|
||||
{
|
||||
return new StringBuilder()
|
||||
.Append($"[{key}]: ")
|
||||
.Append(string.Join("; ", errors))
|
||||
.ToString();
|
||||
};
|
||||
|
||||
return $"{(int)StatusCode} {StatusCode}. {string.Join(Environment.NewLine, valErrors.Select(ve => GetFullError(ve.Key, ve.Value)))}";
|
||||
}
|
||||
|
||||
private class ErrorModel
|
||||
{
|
||||
public string Message { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user