1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Api/ErrorManagement/ApiException.cs

39 lines
965 B
C#
Raw Normal View History

using System;
using Nancy;
using Nancy.Responses;
2013-02-23 23:35:26 +03:00
using NzbDrone.Api.Extensions;
2013-02-19 04:13:42 +03:00
namespace NzbDrone.Api.ErrorManagement
{
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;
}
public JsonResponse<ErrorModel> ToErrorResponse()
{
return new ErrorModel(this).AsResponse(StatusCode);
}
private static string GetMessage(HttpStatusCode statusCode, object content)
{
var result = statusCode.ToString();
if (content != null)
{
result = result + " :" + content;
}
return result;
}
}
}