You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nancy;
|
|
|
|
|
using Nancy.ErrorHandling;
|
|
|
|
|
using NzbDrone.Api.Extentions;
|
|
|
|
|
using NzbDrone.Api.QualityType;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.ErrorManagment
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|