mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
29 lines
750 B
C#
29 lines
750 B
C#
using System;
|
|
using System.Net.Http;
|
|
|
|
namespace Wabbajack.Networking.Http;
|
|
|
|
public class HttpException : Exception
|
|
{
|
|
public HttpException(int code, string reason) : base($"Http Error {code} - {reason}")
|
|
{
|
|
Code = code;
|
|
Reason = reason;
|
|
}
|
|
|
|
public HttpException(HttpResponseMessage response) : base(
|
|
$"Http Error {response.StatusCode} - {response.ReasonPhrase}")
|
|
{
|
|
Code = (int) response.StatusCode;
|
|
Reason = response.ReasonPhrase ?? "Unknown";
|
|
}
|
|
|
|
public string Reason { get; set; }
|
|
public int Code { get; set; }
|
|
|
|
public static void ThrowOnFailure(HttpResponseMessage result)
|
|
{
|
|
if (result.IsSuccessStatusCode) return;
|
|
throw new HttpException(result);
|
|
}
|
|
} |