Skip to content

Commit

Permalink
Changed Test operations to throw JsonPatchTestOperationException fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Aug 14, 2023
1 parent acb4429 commit 933ba44
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
5 changes: 3 additions & 2 deletions SystemTextJsonPatch/Exceptions/ExceptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ internal static void ThrowJsonPatchException(string message)
throw new JsonPatchException(message, null);
}


#if !NETSTANDARD2_0
[DoesNotReturn]
#endif
internal static void ThrowJsonPatchException(JsonPatchError jsonPatchError)
internal static void ThrowJsonPatchTestException(JsonPatchError jsonPatchError)
{
throw new JsonPatchException(jsonPatchError);
throw new JsonPatchTestOperationException(jsonPatchError);
}
}
}
12 changes: 0 additions & 12 deletions SystemTextJsonPatch/Exceptions/JsonPatchException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ namespace SystemTextJsonPatch.Exceptions;
public class JsonPatchException : JsonException
#pragma warning restore CA1032 // Implement standard exception constructors
{
public Operation? FailedOperation { get; }
public object? AffectedObject { get; }

public JsonPatchException(JsonPatchError jsonPatchError, Exception? innerException) : base(jsonPatchError.ErrorMessage, innerException)
{
FailedOperation = jsonPatchError.Operation;
AffectedObject = jsonPatchError.AffectedObject;
}

public JsonPatchException(JsonPatchError jsonPatchError) : this(jsonPatchError, null)
{
}

public JsonPatchException(string message, Exception? innerException) : base(message, innerException)
{
Expand Down
24 changes: 24 additions & 0 deletions SystemTextJsonPatch/Exceptions/JsonPatchTestOperationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using SystemTextJsonPatch.Operations;

namespace SystemTextJsonPatch.Exceptions
{
[Serializable]
#pragma warning disable CA1032 // Implement standard exception constructors
public sealed class JsonPatchTestOperationException : JsonPatchException
#pragma warning restore CA1032 // Implement standard exception constructors
{
public Operation? FailedOperation { get; }
public object? AffectedObject { get; }

public JsonPatchTestOperationException(JsonPatchError jsonPatchError) : base(jsonPatchError.ErrorMessage, null)
{
FailedOperation = jsonPatchError.Operation;
AffectedObject = jsonPatchError.AffectedObject;
}

private JsonPatchTestOperationException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
}
}
}
2 changes: 1 addition & 1 deletion SystemTextJsonPatch/Internal/ErrorReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace SystemTextJsonPatch.Internal;

internal static class ErrorReporter
{
public static readonly Action<JsonPatchError> Default = error => ExceptionHelper.ThrowJsonPatchException(error);
public static readonly Action<JsonPatchError> Default = error => ExceptionHelper.ThrowJsonPatchException(error.ErrorMessage);
}
2 changes: 1 addition & 1 deletion SystemTextJsonPatch/Operations/OperationOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Apply(TModel objectToApplyTo, IObjectAdapter adapter)
break;
}

ExceptionHelper.ThrowJsonPatchException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported));
ExceptionHelper.ThrowJsonPatchTestException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported));
break;
case OperationType.Invalid:
ExceptionHelper.ThrowJsonPatchException(Resources.FormatInvalidJsonPatchOperation(Op));
Expand Down

0 comments on commit 933ba44

Please sign in to comment.