Skip to content

Commit 341c27f

Browse files
committed
[#24] [add] impl
1 parent 2911744 commit 341c27f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Simplify.Web.Json/Model/Binding/JsonModelBinder.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,17 @@ public async Task BindAsync<T>(ModelBinderEventArgs<T> args)
3636
if (string.IsNullOrEmpty(args.Context.RequestBody))
3737
throw new ModelValidationException("JSON request body is null or empty");
3838

39-
var deserializedModel = JsonConvert.DeserializeObject<T>(args.Context.RequestBody, _settings) ?? throw new InvalidOperationException("Deserialized model is null");
40-
41-
args.SetModel(deserializedModel);
39+
try
40+
{
41+
args.SetModel(JsonConvert.DeserializeObject<T>(args.Context.RequestBody, _settings) ?? throw new InvalidOperationException("Deserialized model is null"));
42+
}
43+
catch (JsonReaderException e)
44+
{
45+
throw new ModelValidationException("Error deserializing JSON model. " + e.Message);
46+
}
47+
catch (JsonSerializationException e)
48+
{
49+
throw new ModelValidationException("Error deserializing JSON model. " + e.Message);
50+
}
4251
}
4352
}

0 commit comments

Comments
 (0)