Skip to content

Commit

Permalink
Merge pull request #37 from PandaTechAM/development
Browse files Browse the repository at this point in the history
added more overloads
  • Loading branch information
HaikAsatryan committed Jun 22, 2024
2 parents ba47058 + ce9b72e commit d1fe847
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ InternalServerErrorException.ThrowIfNullOrWhiteSpace(username, "username");
List<string?>? tags = new List<string?> { "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");

Expand Down
8 changes: 8 additions & 0 deletions src/ResponseCrafter/HttpExceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string?>? 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.");
}
}
}
2 changes: 1 addition & 1 deletion src/ResponseCrafter/ResponseCrafter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Copyright>MIT</Copyright>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Version>2.1.2</Version>
<Version>2.1.3</Version>
<PackageId>Pandatech.ResponseCrafter</PackageId>
<PackageTags>Pandatech, library, exception handler, exception, middleware, Api response</PackageTags>
<Title>ResponseCrafter</Title>
Expand Down

0 comments on commit d1fe847

Please sign in to comment.