Radarr/src/Radarr.Http/Exceptions/ApiException.cs

40 lines
1018 B
C#
Raw Normal View History

using System;
using Nancy;
using Nancy.Responses;
2018-11-23 07:03:32 +00:00
using Radarr.Http.ErrorManagement;
using Radarr.Http.Extensions;
2018-11-23 07:03:32 +00:00
namespace Radarr.Http.Exceptions
{
public abstract class ApiException : Exception
{
public object Content { get; private set; }
public HttpStatusCode StatusCode { get; private set; }
protected ApiException(HttpStatusCode statusCode, object content = null)
: base(GetMessage(statusCode, content))
{
StatusCode = statusCode;
Content = content;
}
2019-08-28 21:43:55 +00:00
public JsonResponse<ErrorModel> ToErrorResponse(NancyContext context)
{
2019-08-28 21:43:55 +00:00
return new ErrorModel(this).AsResponse(context, StatusCode);
}
private static string GetMessage(HttpStatusCode statusCode, object content)
{
var result = statusCode.ToString();
if (content != null)
{
result = $"{result}: {content}";
}
return result;
}
}
}