Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Fix - Re-throwing caught exception changes stack information

supportb6768da4db4f
diff --git a/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs b/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs
index 5aa5a154a..0359f428e 100644
--- a/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs
+++ b/src/Core/Grand.Infrastructure/ModelBinding/JsonBodyModelBinder.cs
@@ -20,25 +20,18 @@ public class JsonBodyModelBinder : IModelBinder
var hasJsonContentType = httpContext.Request.ContentType?.Contains("application/json") ?? false;
if (hasJsonContentType)
{
- try
+ string jsonPayload;
+ using (var streamReader = new StreamReader(httpContext.Request.Body))
{
- string jsonPayload;
- using (var streamReader = new StreamReader(httpContext.Request.Body))
- {
- jsonPayload = await streamReader.ReadToEndAsync();
- }
- var options = new JsonSerializerOptions
- {
- PropertyNameCaseInsensitive = true
- };
- options.Converters.Add(new StringConverter());
- bindingContext.Result =
- ModelBindingResult.Success(JsonSerializer.Deserialize(jsonPayload, bindingContext.ModelType, options));
+ jsonPayload = await streamReader.ReadToEndAsync();
}
- catch(Exception ex)
+ var options = new JsonSerializerOptions
{
- throw ex;
- }
+ PropertyNameCaseInsensitive = true
+ };
+ options.Converters.Add(new StringConverter());
+ bindingContext.Result =
+ ModelBindingResult.Success(JsonSerializer.Deserialize(jsonPayload, bindingContext.ModelType, options));
}
else
{