1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs

47 lines
1.3 KiB
C#
Raw Normal View History

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