2013-01-19 07:46:43 +03:00
|
|
|
using System;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy.Responses;
|
2013-02-23 23:35:26 +03:00
|
|
|
using NzbDrone.Api.Extensions;
|
2013-01-19 07:46:43 +03:00
|
|
|
|
2013-02-19 04:13:42 +03:00
|
|
|
namespace NzbDrone.Api.ErrorManagement
|
2013-01-19 07:46:43 +03: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 03:24:49 +03:00
|
|
|
: base(GetMessage(statusCode, content))
|
2013-01-19 07:46:43 +03:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2013-04-17 03:24:49 +03:00
|
|
|
result = result + " :" + content;
|
2013-01-19 07:46:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|