constraint failed exceptions are translated to 409 conflict status codes.

pull/2/head
kayone 11 years ago
parent be3ec7ddb8
commit bbb69a1dc7

@ -1,4 +1,5 @@
using System; using System;
using System.Data.SQLite;
using FluentValidation; using FluentValidation;
using NLog; using NLog;
using Nancy; using Nancy;
@ -48,6 +49,21 @@ namespace NzbDrone.Api.ErrorManagement
}.AsResponse((HttpStatusCode)clientException.StatusCode); }.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); _logger.FatalException("Request Failed", exception);
return new ErrorModel return new ErrorModel

@ -68,6 +68,11 @@
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.84.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Sqlite\System.Data.SQLite.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs"> <Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">

@ -79,6 +79,10 @@
message.message = xmlHttpRequest.responseJSON.message; message.message = xmlHttpRequest.responseJSON.message;
} }
if (xmlHttpRequest.status === 409) {
message.message = xmlHttpRequest.responseJSON.message;
}
else { else {
message.message = '[{0}] {1} : {2}'.format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url); message.message = '[{0}] {1} : {2}'.format(ajaxOptions.type, xmlHttpRequest.statusText, ajaxOptions.url);
} }

Loading…
Cancel
Save