From 770a252756fd2500f91d10e9eaf13e2fe33a61f2 Mon Sep 17 00:00:00 2001 From: Viktor Date: Sat, 8 Jan 2022 11:51:17 +0200 Subject: [PATCH] Changed creating operation errors --- .../OutOfSchool.WebApi/Extensions/OperationExtensions.cs | 9 ++------- .../Extensions/RetrievingResourcesExtensions.cs | 5 ++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/OutOfSchool/OutOfSchool.WebApi/Extensions/OperationExtensions.cs b/OutOfSchool/OutOfSchool.WebApi/Extensions/OperationExtensions.cs index 5a8a17cae5..50653b6052 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Extensions/OperationExtensions.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Extensions/OperationExtensions.cs @@ -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 diff --git a/OutOfSchool/OutOfSchool.WebApi/Extensions/RetrievingResourcesExtensions.cs b/OutOfSchool/OutOfSchool.WebApi/Extensions/RetrievingResourcesExtensions.cs index f80ad16f8a..fbaf286f4f 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Extensions/RetrievingResourcesExtensions.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Extensions/RetrievingResourcesExtensions.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System; +using System.Globalization; using System.Resources; using Google.Protobuf.WellKnownTypes; using OutOfSchool.WebApi.Common; @@ -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); }