1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-28 10:37:41 +00:00
Lidarr/NzbDrone.Api/ErrorManagment/ApiException.cs
kay.one c184595935 added Nancy pipelines for error handling,
cleaned up container registrations.
2013-02-15 16:52:04 -08:00

41 lines
No EOL
1 KiB
C#

using System;
using System.Linq;
using Nancy;
using Nancy.Responses;
using Newtonsoft.Json;
using NzbDrone.Api.QualityType;
namespace NzbDrone.Api.ErrorManagment
{
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;
}
}
}