ApiException.cs 1.0 KB

1234567891011121314151617181920212223
  1. namespace Quadarax.Foundation.Core.Exceptions
  2. {
  3. public partial class ApiException : System.Exception
  4. {
  5. public int StatusCode { get; }
  6. public string Response { get; }
  7. public System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }
  8. public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.Exception innerException)
  9. : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException)
  10. {
  11. StatusCode = statusCode;
  12. Response = response;
  13. Headers = headers;
  14. }
  15. public override string ToString()
  16. {
  17. return $"HTTP Response: \n\n{Response}\n\n{base.ToString()}";
  18. }
  19. }}