Skip to content
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

Issue / Better Error for Corrupted Json #78

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void Configure(LayerConfigurator configurator)
configurator.ConfigureServiceCollection(services =>
{
services.AddSingleton<IExceptionHandler, HandledExceptionHandler>();
services.AddSingleton<IExceptionHandler, GenericADOExceptionHandler>();
});

configurator.ConfigureMiddlewareCollection(middlewares =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using NHibernate.Exceptions;

namespace Do.ExceptionHandling.Default;

public class GenericADOExceptionHandler : IExceptionHandler
cihandeniz marked this conversation as resolved.
Show resolved Hide resolved
{
public bool CanHandle(Exception ex) => ex is GenericADOException;
cihandeniz marked this conversation as resolved.
Show resolved Hide resolved
public ExceptionInfo Handle(Exception ex) =>
new(
(int)((HandledException)ex).StatusCode,
cihandeniz marked this conversation as resolved.
Show resolved Hide resolved
ex.InnerException != null ? ex.InnerException.Message : ex.Message
cihandeniz marked this conversation as resolved.
Show resolved Hide resolved
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public class ObjectUserType : CompositeUserTypeBase
{
if (PropertyTypes[0].NullSafeGet(dr, names, session, owner) is string jsonString)
{
return JsonConvert.DeserializeObject(jsonString);
try
{
return JsonConvert.DeserializeObject(jsonString);
}
catch (JsonReaderException e)
{
throw new InvalidDataException($"Data could not be deserialized to object. Data: {jsonString}", e);
}
}

return null;
Expand Down
4 changes: 4 additions & 0 deletions unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

- `ObjectUserType` was causing its data to be corrupted when it contains special
characters, fixed.

## Improvements

- `GenericADOExceptionHandler` added and server response improved.
cihandeniz marked this conversation as resolved.
Show resolved Hide resolved