Improved results handling in service layer
This commit is contained in:
@@ -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!);
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user