mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-27 01:57:21 +00:00
35 lines
No EOL
1.1 KiB
C#
35 lines
No EOL
1.1 KiB
C#
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);
|
|
}
|
|
}
|
|
} |