Skip to content

Fixed: hide duplicate stacktrace for ModelState errors #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
Expand Down Expand Up @@ -80,7 +81,7 @@ private static Error FromModelError(ModelError modelError, string attributeName,

if (includeExceptionStackTraceInErrors && modelError.Exception != null)
{
error.Meta.IncludeExceptionStackTrace(modelError.Exception);
error.Meta.IncludeExceptionStackTrace(modelError.Exception.Demystify());
}

return error;
Expand Down
4 changes: 3 additions & 1 deletion src/JsonApiDotNetCore/Middleware/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ protected virtual ErrorDocument CreateErrorDocument(Exception exception)

private void ApplyOptions(Error error, Exception exception)
{
error.Meta.IncludeExceptionStackTrace(_options.IncludeExceptionStackTraceInErrors ? exception : null);
Exception resultException = exception is InvalidModelStateException ? null : exception;

error.Meta.IncludeExceptionStackTrace(_options.IncludeExceptionStackTraceInErrors ? resultException : null);
}
}
}
3 changes: 1 addition & 2 deletions src/JsonApiDotNetCore/Serialization/Objects/ErrorMeta.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Newtonsoft.Json;

namespace JsonApiDotNetCore.Serialization.Objects
Expand All @@ -21,7 +20,7 @@ public void IncludeExceptionStackTrace(Exception exception)
}
else
{
Data["StackTrace"] = exception.Demystify().ToString()
Data["StackTrace"] = exception.ToString()
.Split("\n", int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
}
}
Expand Down