2013-07-18 20:47:55 -07:00
|
|
|
using Nancy;
|
2013-01-18 20:46:43 -08:00
|
|
|
using Nancy.ErrorHandling;
|
2013-02-23 12:35:26 -08:00
|
|
|
using NzbDrone.Api.Extensions;
|
2013-01-18 20:46:43 -08:00
|
|
|
|
2013-02-18 17:13:42 -08:00
|
|
|
namespace NzbDrone.Api.ErrorManagement
|
2013-01-18 20:46:43 -08:00
|
|
|
{
|
|
|
|
public class ErrorHandler : IStatusCodeHandler
|
|
|
|
{
|
|
|
|
public bool HandlesStatusCode(HttpStatusCode statusCode, NancyContext context)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Handle(HttpStatusCode statusCode, NancyContext context)
|
|
|
|
{
|
|
|
|
if (statusCode == HttpStatusCode.SeeOther || statusCode == HttpStatusCode.OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (statusCode == HttpStatusCode.Continue)
|
|
|
|
{
|
|
|
|
context.Response = new Response { StatusCode = statusCode };
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-21 17:58:57 -07:00
|
|
|
if (statusCode == HttpStatusCode.Unauthorized)
|
|
|
|
return;
|
|
|
|
|
2013-01-18 20:46:43 -08:00
|
|
|
if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain")
|
|
|
|
context.Response = new ErrorModel
|
|
|
|
{
|
|
|
|
Message = statusCode.ToString()
|
|
|
|
}.AsResponse(statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|