mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
added Nancy pipelines for error handling,
cleaned up container registrations.
This commit is contained in:
33
NzbDrone.Api/ErrorManagment/ErrorHandler.cs
Normal file
33
NzbDrone.Api/ErrorManagment/ErrorHandler.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.ErrorHandling;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user