diff --git a/SeatsioDotNet.Test/ErrorHandlingTest.cs b/SeatsioDotNet.Test/ErrorHandlingTest.cs index 4f82e51..fd5e9c7 100644 --- a/SeatsioDotNet.Test/ErrorHandlingTest.cs +++ b/SeatsioDotNet.Test/ErrorHandlingTest.cs @@ -1,4 +1,6 @@ -using Xunit; +using RestSharp; +using SeatsioDotNet.Util; +using Xunit; namespace SeatsioDotNet.Test { @@ -10,18 +12,28 @@ public void Test4xx() var e = Assert.Throws(() => Client.Events.RetrieveObjectInfo("unexistingEvent", "unexistingObject")); - Assert.StartsWith("Get " + BaseUrl + "/events/unexistingEvent/objects?label=unexistingObject resulted in a 404 Not Found response. Reason: Event not found: unexistingEvent. Request ID:", e.Message); - Assert.Contains(new SeatsioApiError("EVENT_NOT_FOUND", "Event not found: unexistingEvent"), e.Errors); + Assert.Equal("Event not found: unexistingEvent.", e.Message); + Assert.Contains(new SeatsioApiError("EVENT_NOT_FOUND", "Event not found: unexistingEvent"), e.Errors); Assert.NotNull(e.RequestId); } + [Fact] + public void Test5xx() + { + var client = new SeatsioRestClient("https://httpbin.seatsio.net"); + + var e = Assert.Throws(() => RestUtil.AssertOk(client.Execute(new RestRequest("/status/500")))); + + Assert.Equal("Get https://httpbin.seatsio.net/status/500 resulted in a 500 Internal Server Error response. Body: ", e.Message); + } + [Fact] public void WeirdError() { var e = Assert.Throws(() => new SeatsioClient("", null, "unknownProtocol://").Events.RetrieveObjectInfo("unexistingEvent", "unexistingObject")); - Assert.Equal("Get resulted in a 0 response.", e.Message); + Assert.Equal("Get resulted in a 0 response. Body: ", e.Message); Assert.Null(e.Errors); Assert.Null(e.RequestId); } diff --git a/SeatsioDotNet.Test/Events/DeleteEventTest.cs b/SeatsioDotNet.Test/Events/DeleteEventTest.cs index f54b514..cbc451c 100644 --- a/SeatsioDotNet.Test/Events/DeleteEventTest.cs +++ b/SeatsioDotNet.Test/Events/DeleteEventTest.cs @@ -15,7 +15,7 @@ public void Delete() Exception ex = Assert.Throws(() => Client.Events.Retrieve(evnt.Key)); - Assert.Contains("404", ex.Message); + Assert.Equal("Event not found: " + evnt.Key + ".", ex.Message); } } } \ No newline at end of file diff --git a/SeatsioDotNet/RateLimitExceededException.cs b/SeatsioDotNet/RateLimitExceededException.cs index 52bb7e9..e9d06ca 100644 --- a/SeatsioDotNet/RateLimitExceededException.cs +++ b/SeatsioDotNet/RateLimitExceededException.cs @@ -5,8 +5,8 @@ namespace SeatsioDotNet { public class RateLimitExceededException : SeatsioException { - public RateLimitExceededException(List errors, string requestId, RestResponse response) : - base(errors, requestId, response) + public RateLimitExceededException(List errors, string requestId) : + base(errors, requestId) { } } diff --git a/SeatsioDotNet/SeatsioDotNet.csproj b/SeatsioDotNet/SeatsioDotNet.csproj index 62d2fab..1ec2b40 100644 --- a/SeatsioDotNet/SeatsioDotNet.csproj +++ b/SeatsioDotNet/SeatsioDotNet.csproj @@ -2,7 +2,7 @@ Library true - 93.2.0 + 93.3.0 mroloux;bverbeken Official Seats.io .NET API client Official Seats.io .NET API client diff --git a/SeatsioDotNet/SeatsioException.cs b/SeatsioDotNet/SeatsioException.cs index a88149d..ac59236 100644 --- a/SeatsioDotNet/SeatsioException.cs +++ b/SeatsioDotNet/SeatsioException.cs @@ -11,7 +11,8 @@ public class SeatsioException : Exception public readonly List Errors; public readonly string RequestId; - protected SeatsioException(List errors, string requestId, RestResponse response) : base(ExceptionMessage(errors, requestId, response)) + protected SeatsioException(List errors, string requestId) : base( + ExceptionMessage(errors)) { Errors = errors; RequestId = requestId; @@ -21,30 +22,29 @@ private SeatsioException(RestResponse response) : base(ExceptionMessage(response { } - private static string ExceptionMessage(List errors, string requestId, RestResponse response) + private static string ExceptionMessage(List errors) { - string exceptionMessage = ExceptionMessage(response); - exceptionMessage += " Reason: " + String.Join(", ", errors.Select(x => x.Message)) + "."; - exceptionMessage += " Request ID: " + requestId; - return exceptionMessage; + return String.Join(", ", errors.Select(x => x.Message)) + "."; } private static string ExceptionMessage(RestResponse response) { var request = response.Request; - return request.Method + " " + response.ResponseUri + " resulted in a " + (int) response.StatusCode + " " + response.StatusDescription + " response."; + return request.Method + " " + response.ResponseUri + " resulted in a " + (int) response.StatusCode + " " + response.StatusDescription + " response. Body: " + response.Content; } - + public static SeatsioException From(RestResponse response) { if (response.ContentType != null && response.ContentType.Contains("application/json")) { - var parsedException = JsonSerializer.Deserialize(response.Content, SeatsioRestClient.SeatsioJsonSerializerOptions()); + var parsedException = JsonSerializer.Deserialize(response.Content, + SeatsioRestClient.SeatsioJsonSerializerOptions()); if ((int) response.StatusCode == 429) { - return new RateLimitExceededException(parsedException.Errors, parsedException.RequestId, response); + return new RateLimitExceededException(parsedException.Errors, parsedException.RequestId); } - return new SeatsioException(parsedException.Errors, parsedException.RequestId, response); + + return new SeatsioException(parsedException.Errors, parsedException.RequestId); } return new SeatsioException(response);