1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Api/ErrorManagement/ErrorHandler.cs
2013-05-21 17:58:57 -07:00

36 lines
1.1 KiB
C#

using System.Linq;
using Nancy;
using Nancy.ErrorHandling;
using NzbDrone.Api.Extensions;
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 (statusCode == HttpStatusCode.Unauthorized)
return;
if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain")
context.Response = new ErrorModel
{
Message = statusCode.ToString()
}.AsResponse(statusCode);
}
}
}