sonarr-repo-only/NzbDrone.Api/ErrorManagement/ErrorHandler.cs

33 lines
1015 B
C#
Raw Normal View History

using System.Linq;
using Nancy;
using Nancy.ErrorHandling;
using NzbDrone.Api.Extentions;
2013-02-19 01:13:42 +00:00
namespace NzbDrone.Api.ErrorManagement
{
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);
}
}
}