Skip to content

Commit

Permalink
ServiceException now includes the service name.
Browse files Browse the repository at this point in the history
  • Loading branch information
wo80 committed Aug 11, 2020
1 parent 3f81a1f commit a8e2152
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Hqub.Lastfm/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private ServiceException CreateServiceException(Stream stream, HttpResponseMessa

var e = ParseResponseError(doc);

return new ServiceException(e.Error, response.StatusCode, e.Message ?? response.ReasonPhrase);
return new ServiceException(method, e.Error, response.StatusCode, e.Message ?? response.ReasonPhrase);
}

private ResponseError ParseResponseError(XDocument doc)
Expand Down
23 changes: 16 additions & 7 deletions src/Hqub.Lastfm/ServiceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,44 @@ namespace Hqub.Lastfm
public class ServiceException : Exception
{
/// <summary>
/// The last.fm error code.
/// Gets the last.fm service method that caused the exception.
/// </summary>
public string Method { get; private set; }

/// <summary>
/// Gets the last.fm error code.
/// </summary>
public int ErrorCode { get; private set; }

/// <summary>
/// The HTTP status code.
/// Gets the HTTP status code.
/// </summary>
public HttpStatusCode StatusCode { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="ServiceException"/> class.
/// </summary>
/// <param name="method">The Last.fm service method that failed.</param>
/// <param name="error">The error code.</param>
/// <param name="message">The error message.</param>
public ServiceException(int error, string message) : base(message)
public ServiceException(string method, int error, string message) : base(message)
{
this.ErrorCode = error;
Method = method;
ErrorCode = error;
}

/// <summary>
/// Initializes a new instance of the <see cref="ServiceException"/> class.
/// </summary>
/// <param name="method">The last.fm service method that failed.</param>
/// <param name="error">The error code.</param>
/// <param name="statusCode">The HTTP status code.</param>
/// <param name="message">The error message.</param>
public ServiceException(int error, HttpStatusCode statusCode, string message) : base(message)
public ServiceException(string method, int error, HttpStatusCode statusCode, string message) : base(message)
{
this.ErrorCode = error;
this.StatusCode = statusCode;
Method = method;
ErrorCode = error;
StatusCode = statusCode;
}

/// <summary>
Expand Down

0 comments on commit a8e2152

Please sign in to comment.