Skip to content

Commit 420774d

Browse files
claudiamurialdoBeta Bot
authored and
Beta Bot
committed
Cherry pick branch 'genexuslabs:fix/rest-context-timezone' into beta
1 parent 6cec7d4 commit 420774d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

+19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.AspNetCore.Http.Features;
2323
using Microsoft.AspNetCore.Mvc;
2424
using Microsoft.AspNetCore.Mvc.ApplicationModels;
25+
using Microsoft.AspNetCore.Mvc.ModelBinding;
2526
using Microsoft.AspNetCore.Mvc.Routing;
2627
using Microsoft.AspNetCore.Rewrite;
2728
using Microsoft.AspNetCore.Routing;
@@ -126,11 +127,29 @@ public static IApplicationBuilder MapWebSocketManager(this IApplicationBuilder a
126127
}
127128
public class CustomBadRequestObjectResult : ObjectResult
128129
{
130+
static readonly IGXLogger log = GXLoggerFactory.GetLogger(typeof(CustomBadRequestObjectResult).FullName);
129131
public CustomBadRequestObjectResult(ActionContext context)
130132
: base(HttpHelper.GetJsonError(StatusCodes.Status400BadRequest.ToString(), HttpHelper.StatusCodeToTitle(HttpStatusCode.BadRequest)))
131133
{
134+
LogErrorResponse(context);
132135
StatusCode = StatusCodes.Status400BadRequest;
133136
}
137+
static void LogErrorResponse(ActionContext context)
138+
{
139+
if (log.IsErrorEnabled)
140+
{
141+
foreach (KeyValuePair<string, ModelStateEntry> entry in context.ModelState)
142+
{
143+
if (entry.Value.Errors.Count > 0)
144+
{
145+
foreach (ModelError error in entry.Value.Errors)
146+
{
147+
GXLogging.Error(log, "Field ", entry.Key, "Errors:", error.ErrorMessage);
148+
}
149+
}
150+
}
151+
}
152+
}
134153
}
135154

136155
public class Startup

0 commit comments

Comments
 (0)