RaspberryIO/Unosquare.Swan/Exceptions/JsonRequestException.cs
2019-12-03 18:44:25 +01:00

50 lines
1.5 KiB
C#

using System;
namespace Unosquare.Swan.Exceptions {
/// <summary>
/// Represents errors that occurs requesting a JSON file through HTTP.
/// </summary>
/// <seealso cref="System.Exception" />
#if !NETSTANDARD1_3
[Serializable]
#endif
public class JsonRequestException
: Exception {
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:Unosquare.Swan.Exceptions.JsonRequestException" /> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="httpErrorCode">The HTTP error code.</param>
/// <param name="errorContent">Content of the error.</param>
public JsonRequestException(String message, Int32 httpErrorCode = 500, String errorContent = null)
: base(message) {
this.HttpErrorCode = httpErrorCode;
this.HttpErrorContent = errorContent;
}
/// <summary>
/// Gets the HTTP error code.
/// </summary>
/// <value>
/// The HTTP error code.
/// </value>
public Int32 HttpErrorCode {
get;
}
/// <summary>
/// Gets the content of the HTTP error.
/// </summary>
/// <value>
/// The content of the HTTP error.
/// </value>
public String HttpErrorContent {
get;
}
/// <inheritdoc />
public override String ToString() => String.IsNullOrEmpty(this.HttpErrorContent) ? $"HTTP Response Status Code {this.HttpErrorCode} Error Message: {this.HttpErrorContent}" : base.ToString();
}
}