Skip to content

Commit

Permalink
Merge pull request #130 from Archomeda/refactor/temp-request-exceptio…
Browse files Browse the repository at this point in the history
…n-workaround

Rework RequestException temporarily as a less breaking change
  • Loading branch information
Archomeda authored Jun 3, 2023
2 parents 4b461c2 + 30d3f2d commit 8bd1949
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions Gw2Sharp/WebApi/Exceptions/RequestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Gw2Sharp.WebApi.Exceptions
/// <summary>
/// A generic request exception used for the web API.
/// </summary>
public class RequestException : RequestException<string>
public class RequestException : Exception
{
/// <summary>
/// Creates a new <see cref="RequestException" />.
Expand All @@ -15,7 +15,8 @@ public class RequestException : RequestException<string>
/// <param name="message">The message.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, string message) :
base(request, message) { }
this(request, null, message, null)
{ }

/// <summary>
/// Creates a new <see cref="RequestException" />.
Expand All @@ -25,7 +26,8 @@ public RequestException(IWebApiRequest request, string message) :
/// <param name="message">The message.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, IWebApiResponse<string>? response, string message) :
base(request, response, message) { }
this(request, response, message, null)
{ }

/// <summary>
/// Creates a new <see cref="RequestException" />.
Expand All @@ -35,7 +37,8 @@ public RequestException(IWebApiRequest request, IWebApiResponse<string>? respons
/// <param name="innerException">The inner exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, string message, Exception? innerException) :
base(request, message, innerException) { }
this(request, null, message, innerException)
{ }

/// <summary>
/// Creates a new <see cref="RequestException" />.
Expand All @@ -44,17 +47,30 @@ public RequestException(IWebApiRequest request, string message, Exception? inner
/// <param name="response">The response.</param>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, IWebApiResponse<string>? response, string message, Exception innerException) :
base(request, response, message, innerException) { }
public RequestException(IWebApiRequest request, IWebApiResponse<string>? response, string message, Exception? innerException) :
base(message, innerException)
{
this.Request = request ?? throw new ArgumentNullException(nameof(request));
this.Response = response;
}

/// <summary>
/// Gets the original request.
/// </summary>
public IWebApiRequest Request { get; }

/// <summary>
/// Gets the response.
/// </summary>
public IWebApiResponse<string>? Response { get; }
}


/// <summary>
/// A generic request exception used for the web API.
/// </summary>
/// <typeparam name="TResponse">The response object.</typeparam>
public class RequestException<TResponse> : Exception
public class RequestException<TResponse> : RequestException
{
/// <summary>
/// Creates a new <see cref="RequestException{TResponse}" />.
Expand All @@ -63,7 +79,8 @@ public class RequestException<TResponse> : Exception
/// <param name="message">The message.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, string message) :
this(request, null, message, null) { }
this(request, null, message, null)
{ }

/// <summary>
/// Creates a new <see cref="RequestException{TResponse}" />.
Expand All @@ -73,7 +90,8 @@ public RequestException(IWebApiRequest request, string message) :
/// <param name="message">The message.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, IWebApiResponse<TResponse>? response, string message) :
this(request, response, message, null) { }
this(request, response, message, null)
{ }

/// <summary>
/// Creates a new <see cref="RequestException{TResponse}" />.
Expand All @@ -83,7 +101,8 @@ public RequestException(IWebApiRequest request, IWebApiResponse<TResponse>? resp
/// <param name="innerException">The inner exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="request"/> or <paramref name="message"/> is <see langword="null"/>.</exception>
public RequestException(IWebApiRequest request, string message, Exception? innerException) :
this(request, null, message, innerException) { }
this(request, null, message, innerException)
{ }

/// <summary>
/// Creates a new <see cref="RequestException{TResponse}" />.
Expand All @@ -93,20 +112,14 @@ public RequestException(IWebApiRequest request, string message, Exception? inner
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
public RequestException(IWebApiRequest request, IWebApiResponse<TResponse>? response, string message, Exception? innerException) :
base(message, innerException)
base(request, null, message, innerException)
{
this.Request = request ?? throw new ArgumentNullException(nameof(request));
this.Response = response;
}

/// <summary>
/// Gets the original request.
/// </summary>
public IWebApiRequest Request { get; }

/// <summary>
/// Gets the response.
/// </summary>
public IWebApiResponse<TResponse>? Response { get; }
public new IWebApiResponse<TResponse>? Response { get; }
}
}

0 comments on commit 8bd1949

Please sign in to comment.