2013-07-19 06:47:55 +03:00
|
|
|
using Nancy;
|
2013-01-19 07:46:43 +03:00
|
|
|
using Nancy.ErrorHandling;
|
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 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 03:58:57 +03:00
|
|
|
if (statusCode == HttpStatusCode.Unauthorized)
|
|
|
|
return;
|
|
|
|
|
2013-01-19 07:46:43 +03:00
|
|
|
if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain")
|
|
|
|
context.Response = new ErrorModel
|
|
|
|
{
|
|
|
|
Message = statusCode.ToString()
|
|
|
|
}.AsResponse(statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|