1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00
Radarr/NzbDrone.Api/ErrorManagement/ApiException.cs
2013-02-18 17:13:42 -08:00

41 lines
1.0 KiB
C#

using System;
using System.Linq;
using Nancy;
using Nancy.Responses;
using Newtonsoft.Json;
using NzbDrone.Api.Extentions;
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 + " :" + JsonConvert.SerializeObject(content);
}
return result;
}
}
}