Skip to content

Commit 933ba44

Browse files
committed
Changed Test operations to throw JsonPatchTestOperationException fixes #22
1 parent acb4429 commit 933ba44

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

SystemTextJsonPatch/Exceptions/ExceptionHelper.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ internal static void ThrowJsonPatchException(string message)
4747
throw new JsonPatchException(message, null);
4848
}
4949

50+
5051
#if !NETSTANDARD2_0
5152
[DoesNotReturn]
5253
#endif
53-
internal static void ThrowJsonPatchException(JsonPatchError jsonPatchError)
54+
internal static void ThrowJsonPatchTestException(JsonPatchError jsonPatchError)
5455
{
55-
throw new JsonPatchException(jsonPatchError);
56+
throw new JsonPatchTestOperationException(jsonPatchError);
5657
}
5758
}
5859
}

SystemTextJsonPatch/Exceptions/JsonPatchException.cs

-12
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ namespace SystemTextJsonPatch.Exceptions;
99
public class JsonPatchException : JsonException
1010
#pragma warning restore CA1032 // Implement standard exception constructors
1111
{
12-
public Operation? FailedOperation { get; }
13-
public object? AffectedObject { get; }
14-
15-
public JsonPatchException(JsonPatchError jsonPatchError, Exception? innerException) : base(jsonPatchError.ErrorMessage, innerException)
16-
{
17-
FailedOperation = jsonPatchError.Operation;
18-
AffectedObject = jsonPatchError.AffectedObject;
19-
}
20-
21-
public JsonPatchException(JsonPatchError jsonPatchError) : this(jsonPatchError, null)
22-
{
23-
}
2412

2513
public JsonPatchException(string message, Exception? innerException) : base(message, innerException)
2614
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using SystemTextJsonPatch.Operations;
3+
4+
namespace SystemTextJsonPatch.Exceptions
5+
{
6+
[Serializable]
7+
#pragma warning disable CA1032 // Implement standard exception constructors
8+
public sealed class JsonPatchTestOperationException : JsonPatchException
9+
#pragma warning restore CA1032 // Implement standard exception constructors
10+
{
11+
public Operation? FailedOperation { get; }
12+
public object? AffectedObject { get; }
13+
14+
public JsonPatchTestOperationException(JsonPatchError jsonPatchError) : base(jsonPatchError.ErrorMessage, null)
15+
{
16+
FailedOperation = jsonPatchError.Operation;
17+
AffectedObject = jsonPatchError.AffectedObject;
18+
}
19+
20+
private JsonPatchTestOperationException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) : base(serializationInfo, streamingContext)
21+
{
22+
}
23+
}
24+
}

SystemTextJsonPatch/Internal/ErrorReporter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace SystemTextJsonPatch.Internal;
55

66
internal static class ErrorReporter
77
{
8-
public static readonly Action<JsonPatchError> Default = error => ExceptionHelper.ThrowJsonPatchException(error);
8+
public static readonly Action<JsonPatchError> Default = error => ExceptionHelper.ThrowJsonPatchException(error.ErrorMessage);
99
}

SystemTextJsonPatch/Operations/OperationOfT.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Apply(TModel objectToApplyTo, IObjectAdapter adapter)
4747
break;
4848
}
4949

50-
ExceptionHelper.ThrowJsonPatchException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported));
50+
ExceptionHelper.ThrowJsonPatchTestException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported));
5151
break;
5252
case OperationType.Invalid:
5353
ExceptionHelper.ThrowJsonPatchException(Resources.FormatInvalidJsonPatchOperation(Op));

0 commit comments

Comments
 (0)