1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.Api/ErrorManagement/ErrorHandler.cs

36 lines
1.1 KiB
C#
Raw Normal View History

using System.Linq;
using Nancy;
using Nancy.ErrorHandling;
2013-02-23 21:35:26 +01:00
using NzbDrone.Api.Extensions;
2013-02-19 02:13:42 +01: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;
}
2013-05-22 02:58:57 +02:00
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);
}
}
}