2013-07-19 05:47:55 +02:00
|
|
|
|
using Nancy;
|
2013-01-19 05:46:43 +01:00
|
|
|
|
using Nancy.ErrorHandling;
|
2013-02-23 21:35:26 +01:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-01-19 05:46:43 +01:00
|
|
|
|
|
2013-02-19 02:13:42 +01:00
|
|
|
|
namespace NzbDrone.Api.ErrorManagement
|
2013-01-19 05:46:43 +01: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-22 02:58:57 +02:00
|
|
|
|
if (statusCode == HttpStatusCode.Unauthorized)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-01-19 05:46:43 +01:00
|
|
|
|
if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain")
|
|
|
|
|
context.Response = new ErrorModel
|
|
|
|
|
{
|
|
|
|
|
Message = statusCode.ToString()
|
|
|
|
|
}.AsResponse(statusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|