From 793050d018ea358f7de9547d5bb60b7d462aa5d0 Mon Sep 17 00:00:00 2001 From: Haik Date: Sat, 22 Jun 2024 21:01:03 +0400 Subject: [PATCH 1/2] added more overloads --- src/ResponseCrafter/HttpExceptions/NotFoundException.cs | 8 ++++++++ src/ResponseCrafter/ResponseCrafter.csproj | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ResponseCrafter/HttpExceptions/NotFoundException.cs b/src/ResponseCrafter/HttpExceptions/NotFoundException.cs index 24bc226..42978c9 100644 --- a/src/ResponseCrafter/HttpExceptions/NotFoundException.cs +++ b/src/ResponseCrafter/HttpExceptions/NotFoundException.cs @@ -19,4 +19,12 @@ public static void ThrowIfNull(object? value, string? nameOfValue = null) throw new NotFoundException($"{nameOfValue ?? "the_requested_resource"}_was_not_found."); } } + + public static void ThrowIfNullOrWhiteSpace(List? values, string? nameOfValue = null) + { + if (values is null || values.Count == 0 || values.Any(string.IsNullOrWhiteSpace)) + { + throw new BadRequestException($"{nameOfValue ?? "the_requested_resource"}_was_not_found."); + } + } } diff --git a/src/ResponseCrafter/ResponseCrafter.csproj b/src/ResponseCrafter/ResponseCrafter.csproj index 03d55d9..53164db 100644 --- a/src/ResponseCrafter/ResponseCrafter.csproj +++ b/src/ResponseCrafter/ResponseCrafter.csproj @@ -8,7 +8,7 @@ MIT pandatech.png Readme.md - 2.1.2 + 2.1.3 Pandatech.ResponseCrafter Pandatech, library, exception handler, exception, middleware, Api response ResponseCrafter From ce9b72ea7c85d8c41fe154e0928759006e8b5e56 Mon Sep 17 00:00:00 2001 From: Haik Date: Sat, 22 Jun 2024 21:01:25 +0400 Subject: [PATCH 2/2] added more overloads --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 0598b11..1f77ac8 100644 --- a/Readme.md +++ b/Readme.md @@ -141,6 +141,8 @@ InternalServerErrorException.ThrowIfNullOrWhiteSpace(username, "username"); List? tags = new List { "tag1", " ", null }; //For 400 Bad Request BadRequestException.ThrowIfNullOrWhiteSpace(tags, "tags"); +//For 404 Not Found +NotFoundException.ThrowIfNullOrWhiteSpace(tags, "tags"); //For 500 Internal Server Error InternalServerErrorException.ThrowIfNullOrWhiteSpace(tags, "tags");