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