2021-09-27 12:42:46 +00:00
|
|
|
using System;
|
2020-05-20 03:25:41 +00:00
|
|
|
using System.Net.Http;
|
2020-01-07 13:50:11 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.Networking.Http;
|
|
|
|
|
|
|
|
public class HttpException : Exception
|
2020-01-07 13:50:11 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
public HttpException(int code, string reason) : base($"Http Error {code} - {reason}")
|
2020-01-07 13:50:11 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
Code = code;
|
|
|
|
Reason = reason;
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public HttpException(HttpResponseMessage response) : base(
|
|
|
|
$"Http Error {response.StatusCode} - {response.ReasonPhrase}")
|
|
|
|
{
|
|
|
|
Code = (int) response.StatusCode;
|
|
|
|
Reason = response.ReasonPhrase ?? "Unknown";
|
2020-01-07 13:50:11 +00:00
|
|
|
}
|
2021-10-23 16:51:17 +00:00
|
|
|
|
|
|
|
public string Reason { get; set; }
|
|
|
|
public int Code { get; set; }
|
2022-06-08 13:12:44 +00:00
|
|
|
|
|
|
|
public static void ThrowOnFailure(HttpResponseMessage result)
|
|
|
|
{
|
|
|
|
if (result.IsSuccessStatusCode) return;
|
|
|
|
throw new HttpException(result);
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|