2013-01-19 04:46:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nancy;
|
|
|
|
|
using Nancy.Responses;
|
|
|
|
|
using Newtonsoft.Json;
|
2013-01-25 19:03:28 +00:00
|
|
|
|
using NzbDrone.Api.Extentions;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-02-19 01:13:42 +00:00
|
|
|
|
namespace NzbDrone.Api.ErrorManagement
|
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)
|
|
|
|
|
: 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|