1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 18:28:19 +00:00
Sonarr/NzbDrone.Api/ErrorManagment/ErrorPipeline.cs

38 lines
965 B
C#
Raw Normal View History

using System;
using System.Linq;
using NLog;
using Nancy;
2013-01-28 18:06:54 +00:00
using NzbDrone.Api.Extentions;
namespace NzbDrone.Api.ErrorManagment
{
public class ErrorPipeline
{
private readonly Logger _logger;
public ErrorPipeline(Logger logger)
{
_logger = logger;
}
public Response HandleException(NancyContext context, Exception exception)
{
var apiException = exception as ApiException;
2013-01-28 18:06:54 +00:00
if (apiException != null)
{
_logger.WarnException("API Error", apiException);
return apiException.ToErrorResponse();
}
2013-01-28 18:06:54 +00:00
_logger.ErrorException("Unexpected error", exception);
2013-01-28 18:06:54 +00:00
return new ErrorModel()
{
Message = exception.Message,
Description = exception.ToString()
}.AsResponse(HttpStatusCode.InternalServerError);
}
}
}