Skip to content

Commit

Permalink
Merge pull request #496 from EasyPost/bad_request_error
Browse files Browse the repository at this point in the history
feat: maps 400 status codes to BadRequestError class
  • Loading branch information
Justintime50 authored Jul 21, 2023
2 parents 71dce09 + b91253e commit 912f7a3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

- Maps 400 status codes to new `BadRequestError` class

## v5.2.0 (2023-07-12)

- Adds `Hooks` to introspect HTTP requests and responses (see `HTTP Hooks` section of README for more details)
Expand Down
1 change: 1 addition & 0 deletions EasyPost.Tests/ExceptionsTests/ExceptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public async Task TestKnownApiExceptionGeneration()
{ 306, typeof(RedirectError) },
{ 307, typeof(RedirectError) },
{ 308, typeof(RedirectError) },
{ 400, typeof(BadRequestError) },
{ 401, typeof(UnauthorizedError) },
{ 402, typeof(PaymentError) },
{ 403, typeof(UnauthorizedError) },
Expand Down
1 change: 1 addition & 0 deletions EasyPost/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static class Constants
{ 306, typeof(RedirectError) },
{ 307, typeof(RedirectError) },
{ 308, typeof(RedirectError) },
{ 400, typeof(BadRequestError) },
{ 401, typeof(UnauthorizedError) },
{ 402, typeof(PaymentError) },
{ 403, typeof(UnauthorizedError) },
Expand Down
23 changes: 23 additions & 0 deletions EasyPost/Exceptions/API/BadRequestError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using EasyPost.Models.API;

namespace EasyPost.Exceptions.API
{
/// <summary>
/// Represents an error that occurs when an bad request is made to the EasyPost API.
/// </summary>
public class BadRequestError : ApiError
{
/// <summary>
/// Initializes a new instance of the <see cref="BadRequestError" /> class.
/// </summary>
/// <param name="errorMessage">The error message to print to console.</param>
/// <param name="statusCode">Optional HTTP status code to store as a property.</param>
/// <param name="errorType">Optional error type string to store as a property.</param>
/// <param name="errors">Optional list of <see cref="Error"/> objects to store as a property.</param>
internal BadRequestError(string errorMessage, int statusCode, string? errorType = null, List<Error>? errors = null)
: base(errorMessage, statusCode, errorType, errors)
{
}
}
}

0 comments on commit 912f7a3

Please sign in to comment.