Improved results handling in service layer

This commit is contained in:
2026-09-11 10:32:51 +02:00
parent 66f720a20b
commit a15b25248d
11 changed files with 87 additions and 103 deletions
@@ -33,9 +33,9 @@ public sealed class BrowserLocalStorageService(ProtectedLocalStorage storage)
{
var retrieval = await storage.GetAsync<string>(key);
return retrieval.Success && !string.IsNullOrWhiteSpace(retrieval.Value)
? Result.Ok(retrieval.Value)
: Result.Fail(NotFoundError.Create($"Could not find object by key {key}"));
return Result.FailIf(!retrieval.Success && string.IsNullOrWhiteSpace(retrieval.Value),
NotFoundError.Create($"Could not find object by key {key}"))
.ToResult(retrieval.Value!);
}));
public async ValueTask<Result<TValue>> GetAsync<TValue>(string key) where TValue : class =>
@@ -43,8 +43,8 @@ public sealed class BrowserLocalStorageService(ProtectedLocalStorage storage)
{
var retrieval = await storage.GetAsync<TValue>(key);
return retrieval.Success && retrieval.Value is not null
? Result.Ok(retrieval.Value)
: Result.Fail(NotFoundError.Create($"Could not find object by key {key}"));
return Result.FailIf(!retrieval.Success && retrieval.Value is null,
NotFoundError.Create($"Could not find object by key {key}"))
.ToResult(retrieval.Value!);
}));
}