- fix: profiles token refresh now
This commit is contained in:
@@ -74,6 +74,19 @@ public sealed record AuthDenyError(string[] Errors, AuthenticateDenyCode Code);
|
||||
public sealed class AuthException(AuthDenyError error) : Exception
|
||||
{
|
||||
public AuthDenyError Error { get; } = error;
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
var str = "Error while logging in. Please try again. " + Error.Code;
|
||||
foreach (var error in Error.Errors)
|
||||
{
|
||||
str += "\n" + error;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
|
||||
@@ -32,20 +32,6 @@ public class RestService
|
||||
var response = await _client.GetAsync(uri, cancellationToken);
|
||||
return await ReadResult<T>(response, cancellationToken, uri);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<T> GetAsyncDefault<T>(Uri uri, T defaultValue, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
try
|
||||
{
|
||||
return await GetAsync<T>(uri, cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<K> PostAsync<K, T>(T information, Uri uri, CancellationToken cancellationToken) where K : notnull
|
||||
{
|
||||
@@ -71,6 +57,20 @@ public class RestService
|
||||
var response = await _client.DeleteAsync(uri, cancellationToken);
|
||||
return await ReadResult<T>(response, cancellationToken, uri);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<T> GetAsyncDefault<T>(Uri uri, T defaultValue, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
try
|
||||
{
|
||||
return await GetAsync<T>(uri, cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private async Task<T> ReadResult<T>(HttpResponseMessage response, CancellationToken cancellationToken, Uri uri) where T : notnull
|
||||
|
||||
19
Nebula.Shared/Utils/ExceptionHelper.cs
Normal file
19
Nebula.Shared/Utils/ExceptionHelper.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Nebula.Shared.Utils;
|
||||
|
||||
public static class ExceptionHelper
|
||||
{
|
||||
public static Task<T> TryRun<T>(Func<Task<T>> func, int attempts = 3, Action<int, Exception>? attemptsCallback = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return func.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (attempts <= 0) throw new("Attempts was expired! ", e);
|
||||
attempts--;
|
||||
attemptsCallback?.Invoke(attempts, e);
|
||||
return TryRun(func, attempts);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user