Skip to content

Commit

Permalink
Changed creating operation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
strivitech committed Jan 10, 2022
1 parent f6431f7 commit 770a252
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ public static class OperationExtensions
{
public static OperationError GetOperationError(this ImagesOperationErrorCode code)
{
var resourceKey = code.GetResourceKey();

_ = resourceKey ?? throw new InvalidOperationException(
$"Unreal to get the resource key from {code} in {nameof(ImagesOperationErrorCode)}.");

return CreateOperationError(code.ToString(), RetrievingResourcesExtensions.GetStringFromResources(ResourceManagers.ImageResourceManager, resourceKey));
return CreateOperationError(code.ToString(), code.GetResourceValue());
}

public static OperationError CreateOperationError(string code, string description)
{
if (string.IsNullOrEmpty(code))
{
throw new ArgumentNullException(nameof(code));
throw new ArgumentException(@$"Code [{code}] cannot be null or empty.", nameof(code));
}

return new OperationError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System;
using System.Globalization;
using System.Resources;
using Google.Protobuf.WellKnownTypes;
using OutOfSchool.WebApi.Common;
Expand All @@ -21,6 +22,8 @@ public static string GetResourceValue(this ImagesOperationErrorCode code, Cultur

internal static string GetStringFromResources(ResourceManager resourceManager, string resourceKey, CultureInfo culture = null)
{
_ = resourceManager ?? throw new ArgumentNullException(nameof(resourceManager));

return string.IsNullOrEmpty(resourceKey) ? null :
resourceManager.GetString(resourceKey, culture);
}
Expand Down

0 comments on commit 770a252

Please sign in to comment.