From 9ee2eb1326c105f913d39856d0a6f4d6dcb0a1be Mon Sep 17 00:00:00 2001 From: Andrei-hub11 Date: Sun, 9 Jun 2024 21:01:59 -0300 Subject: [PATCH] Adding the TooManyRequests error type --- src/Errors/Error.cs | 12 ++++++++++++ src/Errors/ErrorType.cs | 1 + tests/Errors/ErrorTests.cs | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/Errors/Error.cs b/src/Errors/Error.cs index c42b9f6..2aee64c 100644 --- a/src/Errors/Error.cs +++ b/src/Errors/Error.cs @@ -123,6 +123,18 @@ public static Error Forbidden( Dictionary? metadata = null) => new(code, description, ErrorType.Forbidden, metadata); + /// + /// Creates an of type from a code and description. + /// + /// The unique error code. + /// The error description. + /// A dictionary which provides optional space for information. + public static Error TooManyRequests( + string code = "General.TooManyRequests", + string description = "A 'Too Many Requests' error has occurred.", + Dictionary? metadata = null) => + new(code, description, ErrorType.TooManyRequests, metadata); + /// /// Creates an with the given numeric , /// , and . diff --git a/src/Errors/ErrorType.cs b/src/Errors/ErrorType.cs index d0536fa..2f4a72c 100644 --- a/src/Errors/ErrorType.cs +++ b/src/Errors/ErrorType.cs @@ -12,4 +12,5 @@ public enum ErrorType NotFound, Unauthorized, Forbidden, + TooManyRequests, } diff --git a/tests/Errors/ErrorTests.cs b/tests/Errors/ErrorTests.cs index dc5da44..c0fd91a 100644 --- a/tests/Errors/ErrorTests.cs +++ b/tests/Errors/ErrorTests.cs @@ -83,6 +83,16 @@ public void CreateError_WhenForbiddenError_ShouldHaveErrorTypeForbidden() ValidateError(error, expectedErrorType: ErrorType.Forbidden); } + [Fact] + public void CreateError_WhenTooManyRequestsError_ShouldHaveErrorTypeTooManyRequests() + { + // Act + Error error = Error.TooManyRequests(ErrorCode, ErrorDescription, Dictionary); + + // Assert + ValidateError(error, expectedErrorType: ErrorType.TooManyRequests); + } + [Fact] public void CreateError_WhenCustomType_ShouldHaveCustomErrorType() {