From bbb69a1dc7d7b6073a722c8fd61f987a9a9fc8b8 Mon Sep 17 00:00:00 2001 From: kayone Date: Sun, 1 Dec 2013 16:02:32 -0800 Subject: [PATCH] constraint failed exceptions are translated to 409 conflict status codes. --- .../ErrorManagement/NzbDroneErrorPipeline.cs | 16 ++++++++++++++++ src/NzbDrone.Api/NzbDrone.Api.csproj | 5 +++++ src/UI/Instrumentation/ErrorHandler.js | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/src/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs b/src/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs index 236bcc8df..c7f5cbd36 100644 --- a/src/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs +++ b/src/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs @@ -1,4 +1,5 @@ using System; +using System.Data.SQLite; using FluentValidation; using NLog; using Nancy; @@ -48,6 +49,21 @@ namespace NzbDrone.Api.ErrorManagement }.AsResponse((HttpStatusCode)clientException.StatusCode); } + + if (context.Request.Method == "PUT" || context.Request.Method == "POST") + { + var sqLiteException = exception as SQLiteException; + + if (sqLiteException != null) + { + if (sqLiteException.Message.Contains("constraint failed")) + return new ErrorModel + { + Message = exception.Message, + }.AsResponse(HttpStatusCode.Conflict); + } + } + _logger.FatalException("Request Failed", exception); return new ErrorModel diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index 939dcd9ef..9569bf6f3 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -68,6 +68,11 @@ + + + False + ..\Libraries\Sqlite\System.Data.SQLite.dll + diff --git a/src/UI/Instrumentation/ErrorHandler.js b/src/UI/Instrumentation/ErrorHandler.js index 0de3744dd..d74eafc22 100644 --- a/src/UI/Instrumentation/ErrorHandler.js +++ b/src/UI/Instrumentation/ErrorHandler.js @@ -79,6 +79,10 @@ message.message = xmlHttpRequest.responseJSON.message; } + if (xmlHttpRequest.status === 409) { + message.message = xmlHttpRequest.responseJSON.message; + } + else { message.message = '[{0}] {1} : {2}'.format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url); }