mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Better response if invalid JSON is received through the API
This commit is contained in:
parent
7d131fbb3d
commit
e325a5c27e
@ -30,7 +30,7 @@ private static string GetMessage(HttpStatusCode statusCode, object content)
|
|||||||
|
|
||||||
if (content != null)
|
if (content != null)
|
||||||
{
|
{
|
||||||
result = result + " :" + content;
|
result = $"{result}: {content}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Nancy;
|
using Nancy;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using Sonarr.Http.Extensions;
|
using Sonarr.Http.Extensions;
|
||||||
|
|
||||||
@ -194,8 +195,16 @@ protected Action<TResource> UpdateResource
|
|||||||
|
|
||||||
protected TResource ReadResourceFromRequest(bool skipValidate = false)
|
protected TResource ReadResourceFromRequest(bool skipValidate = false)
|
||||||
{
|
{
|
||||||
//TODO: handle when request is null
|
TResource resource;
|
||||||
var resource = Request.Body.FromJson<TResource>();
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resource = Request.Body.FromJson<TResource>();
|
||||||
|
}
|
||||||
|
catch (JsonReaderException e)
|
||||||
|
{
|
||||||
|
throw new BadRequestException($"Invalid request body. {e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
if (resource == null)
|
if (resource == null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user