1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00
Radarr/NzbDrone.Api/ErrorManagement/ErrorPipeline.cs
2013-02-23 12:35:26 -08:00

38 lines
966 B
C#

using System;
using System.Linq;
using NLog;
using Nancy;
using NzbDrone.Api.Extensions;
namespace NzbDrone.Api.ErrorManagement
{
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;
if (apiException != null)
{
_logger.WarnException("API Error", apiException);
return apiException.ToErrorResponse();
}
_logger.ErrorException("Unexpected error", exception);
return new ErrorModel()
{
Message = exception.Message,
Description = exception.ToString()
}.AsResponse(HttpStatusCode.InternalServerError);
}
}
}