- fix: profiles token refresh now

This commit is contained in:
2025-08-17 21:02:45 +03:00
parent 6c967efd85
commit b86b65fd66
6 changed files with 86 additions and 33 deletions

View File

@@ -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))]

View File

@@ -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

View 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);
}
}
}