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

47 lines
1.3 KiB
C#
Raw Normal View History

using System;
2013-04-21 00:14:41 +02:00
using FluentValidation;
using NLog;
using Nancy;
2013-02-23 21:35:26 +01:00
using NzbDrone.Api.Extensions;
using HttpStatusCode = Nancy.HttpStatusCode;
2013-02-19 02:13:42 +01:00
namespace NzbDrone.Api.ErrorManagement
{
2013-05-11 01:53:50 +02:00
public class NzbDroneErrorPipeline
{
private readonly Logger _logger;
2013-05-11 01:53:50 +02:00
public NzbDroneErrorPipeline(Logger logger)
{
_logger = logger;
}
public Response HandleException(NancyContext context, Exception exception)
{
var apiException = exception as ApiException;
2013-01-28 19:06:54 +01:00
if (apiException != null)
{
_logger.WarnException("API Error", apiException);
return apiException.ToErrorResponse();
}
2013-01-28 19:06:54 +01:00
2013-04-21 00:14:41 +02:00
var validationException = exception as ValidationException;
if (validationException != null)
{
_logger.Warn("Invalid request {0}", validationException.Message);
2013-04-21 00:14:41 +02:00
return validationException.Errors.AsResponse(HttpStatusCode.BadRequest);
}
2013-05-04 04:15:46 +02:00
_logger.FatalException("Request Failed", exception);
2013-01-28 19:06:54 +01:00
return new ErrorModel()
{
Message = exception.Message,
Description = exception.ToString()
2013-01-28 19:06:54 +01:00
}.AsResponse(HttpStatusCode.InternalServerError);
}
}
}