From b2cce4d4f063a2a1683c7e036c054745d1600094 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 29 Feb 2012 22:38:42 -0800 Subject: [PATCH] Reportingare.ReportException are now routed to ExceptionController --- .../Controllers/ExceptionController.cs | 51 +++++++++-------- .../Controllers/ReportingController.cs | 55 +++++++++---------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs index 502b7a45d..11c119b60 100644 --- a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs +++ b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ExceptionController.cs @@ -17,29 +17,29 @@ namespace NzbDrone.Services.Service.Controllers { _database = database; } - + [HttpPost] public EmptyResult ReportExisting(ExistingExceptionReport existingExceptionReport) { try { - if (ExceptionHashExists(existingExceptionReport.Hash)) - { - - var exceptionInstance = new ExceptionInstance - { - ExceptionHash = existingExceptionReport.Hash, - IsProduction = existingExceptionReport.IsProduction, - LogMessage = existingExceptionReport.LogMessage, - Timestamp = DateTime.Now - }; - - _database.Insert(exceptionInstance); - } - else - { - logger.Warn("Invalid exception hash '{0}'", existingExceptionReport.Hash); - } + if (ExceptionHashExists(existingExceptionReport.Hash)) + { + + var exceptionInstance = new ExceptionInstance + { + ExceptionHash = existingExceptionReport.Hash, + IsProduction = existingExceptionReport.IsProduction, + LogMessage = existingExceptionReport.LogMessage, + Timestamp = DateTime.Now + }; + + _database.Insert(exceptionInstance); + } + else + { + logger.Warn("Invalid exception hash '{0}'", existingExceptionReport.Hash); + } } catch (Exception e) { @@ -49,7 +49,7 @@ namespace NzbDrone.Services.Service.Controllers return new EmptyResult(); } - + [HttpPost] public JsonResult ReportNew(ExceptionReport exceptionReport) { @@ -72,14 +72,19 @@ namespace NzbDrone.Services.Service.Controllers catch (Exception e) { logger.FatalException("Error has occurred while saving exception", e); - throw; + if (!exceptionReport.IsProduction) + { + throw; + } } + + return new JsonResult(); } - + private string GetExceptionDetailId(ExceptionReport exceptionReport) { var reportHash = Hash(String.Concat(exceptionReport.Version, exceptionReport.String, exceptionReport.Logger)); - + if (!ExceptionHashExists(reportHash)) { var exeptionDetail = new ExceptionDetail(); @@ -89,7 +94,7 @@ namespace NzbDrone.Services.Service.Controllers exeptionDetail.Type = exceptionReport.Type; exeptionDetail.Version = exceptionReport.Version; - _database.Insert(exeptionDetail); + _database.Insert(exeptionDetail); } return reportHash; diff --git a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs index f3a336a6b..f1af9cb37 100644 --- a/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs +++ b/NzbDrone.Services/NzbDrone.Services.Service/Controllers/ReportingController.cs @@ -13,30 +13,47 @@ namespace NzbDrone.Services.Service.Controllers public class ReportingController : Controller { private readonly IDatabase _database; + private readonly ExceptionController _exceptionController; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private const string OK = "OK"; - public ReportingController(IDatabase database) + public ReportingController(IDatabase database, ExceptionController exceptionController) { _database = database; + _exceptionController = exceptionController; } [HttpPost] public JsonResult ParseError(ParseErrorReport parseErrorReport) { - logger.Trace(parseErrorReport.NullSafe()); + try + { - if (ParseErrorExists(parseErrorReport.Title)) - return Json(OK); - var row = new ParseErrorRow(); - row.LoadBase(parseErrorReport); - row.Title = parseErrorReport.Title; + logger.Trace(parseErrorReport.NullSafe()); - _database.Insert(row); + if (ParseErrorExists(parseErrorReport.Title)) + return Json(OK); + + var row = new ParseErrorRow(); + row.LoadBase(parseErrorReport); + row.Title = parseErrorReport.Title; + + _database.Insert(row); + + return Json(OK); + } + catch (Exception e) + { + logger.FatalException("Error has occurred while saving parse report", e); + if (!parseErrorReport.IsProduction) + { + throw; + } + } - return Json(OK); + return new JsonResult(); } @@ -48,25 +65,7 @@ namespace NzbDrone.Services.Service.Controllers [HttpPost] public JsonResult ReportException(ExceptionReport exceptionReport) { - try - { - var row = new ExceptionRow(); - row.LoadBase(exceptionReport); - row.LogMessage = exceptionReport.LogMessage; - row.Logger = exceptionReport.Logger; - row.String = exceptionReport.String; - row.Type = exceptionReport.Type; - - _database.Insert(row); - - return Json(OK); - } - catch (Exception) - { - logger.Trace(exceptionReport.NullSafe()); - throw; - } - + return _exceptionController.ReportNew(exceptionReport); } } } \ No newline at end of file