2013-01-19 04:46:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using Nancy;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.ErrorManagment
|
|
|
|
|
{
|
|
|
|
|
public class ErrorPipeline
|
|
|
|
|
{
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public ErrorPipeline(Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Response HandleException(NancyContext context, Exception exception)
|
|
|
|
|
{
|
2013-01-20 00:19:27 +00:00
|
|
|
|
var apiException = exception as ApiException;
|
|
|
|
|
|
|
|
|
|
if (apiException != null)
|
2013-01-19 04:46:43 +00:00
|
|
|
|
{
|
2013-01-20 00:19:27 +00:00
|
|
|
|
_logger.WarnException("API Error", apiException);
|
|
|
|
|
return apiException.ToErrorResponse();
|
2013-01-19 04:46:43 +00:00
|
|
|
|
}
|
2013-01-20 00:19:27 +00:00
|
|
|
|
|
2013-01-19 04:46:43 +00:00
|
|
|
|
_logger.ErrorException("Unexpected error", exception);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|