2013-01-19 07:46:43 +03:00
|
|
|
using System.Linq;
|
|
|
|
using Nancy;
|
|
|
|
using Nancy.ErrorHandling;
|
2013-01-25 22:03:28 +03:00
|
|
|
using NzbDrone.Api.Extentions;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain")
|
|
|
|
context.Response = new ErrorModel
|
|
|
|
{
|
|
|
|
Message = statusCode.ToString()
|
|
|
|
}.AsResponse(statusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|