Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the TooManyRequests error type #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Errors/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public static Error Forbidden(
Dictionary<string, object>? metadata = null) =>
new(code, description, ErrorType.Forbidden, metadata);

/// <summary>
/// Creates an <see cref="Error"/> of type <see cref="ErrorType.TooManyRequests"/> from a code and description.
/// </summary>
/// <param name="code">The unique error code.</param>
/// <param name="description">The error description.</param>
/// <param name="metadata">A dictionary which provides optional space for information.</param>
public static Error TooManyRequests(
string code = "General.TooManyRequests",
string description = "A 'Too Many Requests' error has occurred.",
Dictionary<string, object>? metadata = null) =>
new(code, description, ErrorType.TooManyRequests, metadata);

/// <summary>
/// Creates an <see cref="Error"/> with the given numeric <paramref name="type"/>,
/// <paramref name="code"/>, and <paramref name="description"/>.
Expand Down
1 change: 1 addition & 0 deletions src/Errors/ErrorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public enum ErrorType
NotFound,
Unauthorized,
Forbidden,
TooManyRequests,
}
10 changes: 10 additions & 0 deletions tests/Errors/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down