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