Skip to content

Commit 7f9015d

Browse files
committed
return 409 for mismatching data types
1 parent 8e94205 commit 7f9015d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/JsonApiDotNetCore/Internal/JsonApiExceptionFactory.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ public static JsonApiException GetException(Exception exception)
88
{
99
var exceptionType = exception.GetType();
1010

11-
if(exceptionType == typeof(JsonApiException))
11+
if (exceptionType == typeof(JsonApiException))
1212
return (JsonApiException)exception;
13-
13+
14+
// TODO: this is for mismatching type requests (e.g. posting an author to articles endpoint)
15+
// however, we can't actually guarantee that this is the source of this exception
16+
// we should probably use an action filter or when we improve the ContextGraph
17+
// we might be able to skip most of deserialization entirely by checking the JToken
18+
// directly
19+
if (exceptionType == typeof(InvalidCastException))
20+
return new JsonApiException(409, exception.Message, exception);
21+
1422
return new JsonApiException(500, exceptionType.Name, exception);
1523
}
1624
}

src/JsonApiDotNetCore/api/.manifest

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"JsonApiDotNetCore.Configuration.JsonApiOptions.BuildContextGraph``1(System.Action{JsonApiDotNetCore.Builders.IContextGraphBuilder})": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
5555
"JsonApiDotNetCore.Configuration.JsonApiOptions.ContextGraph": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
5656
"JsonApiDotNetCore.Configuration.JsonApiOptions.DefaultPageSize": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
57+
"JsonApiDotNetCore.Configuration.JsonApiOptions.DisableErrorSource": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
58+
"JsonApiDotNetCore.Configuration.JsonApiOptions.DisableErrorStackTraces": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
5759
"JsonApiDotNetCore.Configuration.JsonApiOptions.EnableExtension(JsonApiDotNetCore.Models.JsonApiExtension)": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
5860
"JsonApiDotNetCore.Configuration.JsonApiOptions.EnableOperations": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
5961
"JsonApiDotNetCore.Configuration.JsonApiOptions.IncludeTotalRecordCount": "JsonApiDotNetCore.Configuration.JsonApiOptions.yml",
@@ -261,11 +263,15 @@
261263
"JsonApiDotNetCore.Internal.DasherizedRoutingConvention.Apply(Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModel)": "JsonApiDotNetCore.Internal.DasherizedRoutingConvention.yml",
262264
"JsonApiDotNetCore.Internal.Error": "JsonApiDotNetCore.Internal.Error.yml",
263265
"JsonApiDotNetCore.Internal.Error.#ctor": "JsonApiDotNetCore.Internal.Error.yml",
264-
"JsonApiDotNetCore.Internal.Error.#ctor(System.Int32,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
265-
"JsonApiDotNetCore.Internal.Error.#ctor(System.Int32,System.String,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
266-
"JsonApiDotNetCore.Internal.Error.#ctor(System.String,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
267-
"JsonApiDotNetCore.Internal.Error.#ctor(System.String,System.String,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
266+
"JsonApiDotNetCore.Internal.Error.#ctor(System.Int32,System.String,JsonApiDotNetCore.Internal.ErrorMeta,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
267+
"JsonApiDotNetCore.Internal.Error.#ctor(System.Int32,System.String,System.String,JsonApiDotNetCore.Internal.ErrorMeta,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
268+
"JsonApiDotNetCore.Internal.Error.#ctor(System.String,System.String,JsonApiDotNetCore.Internal.ErrorMeta,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
269+
"JsonApiDotNetCore.Internal.Error.#ctor(System.String,System.String,System.String,JsonApiDotNetCore.Internal.ErrorMeta,System.String)": "JsonApiDotNetCore.Internal.Error.yml",
268270
"JsonApiDotNetCore.Internal.Error.Detail": "JsonApiDotNetCore.Internal.Error.yml",
271+
"JsonApiDotNetCore.Internal.Error.Meta": "JsonApiDotNetCore.Internal.Error.yml",
272+
"JsonApiDotNetCore.Internal.Error.ShouldSerializeMeta": "JsonApiDotNetCore.Internal.Error.yml",
273+
"JsonApiDotNetCore.Internal.Error.ShouldSerializeSource": "JsonApiDotNetCore.Internal.Error.yml",
274+
"JsonApiDotNetCore.Internal.Error.Source": "JsonApiDotNetCore.Internal.Error.yml",
269275
"JsonApiDotNetCore.Internal.Error.Status": "JsonApiDotNetCore.Internal.Error.yml",
270276
"JsonApiDotNetCore.Internal.Error.StatusCode": "JsonApiDotNetCore.Internal.Error.yml",
271277
"JsonApiDotNetCore.Internal.Error.Title": "JsonApiDotNetCore.Internal.Error.yml",
@@ -274,6 +280,9 @@
274280
"JsonApiDotNetCore.Internal.ErrorCollection.Add(JsonApiDotNetCore.Internal.Error)": "JsonApiDotNetCore.Internal.ErrorCollection.yml",
275281
"JsonApiDotNetCore.Internal.ErrorCollection.Errors": "JsonApiDotNetCore.Internal.ErrorCollection.yml",
276282
"JsonApiDotNetCore.Internal.ErrorCollection.GetJson": "JsonApiDotNetCore.Internal.ErrorCollection.yml",
283+
"JsonApiDotNetCore.Internal.ErrorMeta": "JsonApiDotNetCore.Internal.ErrorMeta.yml",
284+
"JsonApiDotNetCore.Internal.ErrorMeta.FromException(System.Exception)": "JsonApiDotNetCore.Internal.ErrorMeta.yml",
285+
"JsonApiDotNetCore.Internal.ErrorMeta.StackTrace": "JsonApiDotNetCore.Internal.ErrorMeta.yml",
277286
"JsonApiDotNetCore.Internal.Generics": "JsonApiDotNetCore.Internal.Generics.yml",
278287
"JsonApiDotNetCore.Internal.Generics.GenericProcessor`1": "JsonApiDotNetCore.Internal.Generics.GenericProcessor-1.yml",
279288
"JsonApiDotNetCore.Internal.Generics.GenericProcessor`1.#ctor(JsonApiDotNetCore.Data.IDbContextResolver)": "JsonApiDotNetCore.Internal.Generics.GenericProcessor-1.yml",
@@ -300,11 +309,11 @@
300309
"JsonApiDotNetCore.Internal.JsonApiException": "JsonApiDotNetCore.Internal.JsonApiException.yml",
301310
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(JsonApiDotNetCore.Internal.Error)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
302311
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(JsonApiDotNetCore.Internal.ErrorCollection)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
303-
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.Int32,System.String)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
304312
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.Int32,System.String,System.Exception)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
305313
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.Int32,System.String,System.String)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
306-
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.String,System.String)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
314+
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.Int32,System.String,System.String,System.String)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
307315
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.String,System.String,System.String)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
316+
"JsonApiDotNetCore.Internal.JsonApiException.#ctor(System.String,System.String,System.String,System.String)": "JsonApiDotNetCore.Internal.JsonApiException.yml",
308317
"JsonApiDotNetCore.Internal.JsonApiException.GetError": "JsonApiDotNetCore.Internal.JsonApiException.yml",
309318
"JsonApiDotNetCore.Internal.JsonApiException.GetStatusCode": "JsonApiDotNetCore.Internal.JsonApiException.yml",
310319
"JsonApiDotNetCore.Internal.JsonApiExceptionFactory": "JsonApiDotNetCore.Internal.JsonApiExceptionFactory.yml",

0 commit comments

Comments
 (0)