Skip to content

Commit

Permalink
feat: rename JsonRpcPreDefinedErrorCodes to JsonRpcErrorCodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ekonyukov committed Aug 28, 2024
1 parent 919cca2 commit f80e2bf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Tochka.JsonRpc.Common;

/// <summary>
/// Reserved pre-defined JSON-RPC error codes
/// Reserved predefined JSON-RPC error codes
/// </summary>
public static class JsonRpcPreDefinedErrorCodes
public static class JsonRpcErrorCodes
{
/// <summary>
/// Invalid JSON was received by the server.
Expand Down
12 changes: 6 additions & 6 deletions src/Tochka.JsonRpc.Common/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ Tochka.JsonRpc.Common.Features.JsonRpcFeature.RawCall.set -> void
Tochka.JsonRpc.Common.Features.JsonRpcFeature.Response.get -> Tochka.JsonRpc.Common.Models.Response.IResponse?
Tochka.JsonRpc.Common.Features.JsonRpcFeature.Response.set -> void
const Tochka.JsonRpc.Common.JsonRpcConstants.OutgoingHttpRequestOptionMethodNameKey = "tochka_outgoing_http_request_method_name" -> string!
const Tochka.JsonRpc.Common.JsonRpcPreDefinedErrorCodes.InternalError = -32603 -> int
const Tochka.JsonRpc.Common.JsonRpcPreDefinedErrorCodes.InvalidParams = -32602 -> int
const Tochka.JsonRpc.Common.JsonRpcPreDefinedErrorCodes.InvalidRequest = -32600 -> int
const Tochka.JsonRpc.Common.JsonRpcPreDefinedErrorCodes.MethodNotFound = -32601 -> int
const Tochka.JsonRpc.Common.JsonRpcPreDefinedErrorCodes.ParseError = -32700 -> int
Tochka.JsonRpc.Common.JsonRpcPreDefinedErrorCodes
const Tochka.JsonRpc.Common.JsonRpcErrorCodes.InternalError = -32603 -> int
const Tochka.JsonRpc.Common.JsonRpcErrorCodes.InvalidParams = -32602 -> int
const Tochka.JsonRpc.Common.JsonRpcErrorCodes.InvalidRequest = -32600 -> int
const Tochka.JsonRpc.Common.JsonRpcErrorCodes.MethodNotFound = -32601 -> int
const Tochka.JsonRpc.Common.JsonRpcErrorCodes.ParseError = -32700 -> int
Tochka.JsonRpc.Common.JsonRpcErrorCodes
20 changes: 10 additions & 10 deletions src/Tochka.JsonRpc.Server/Services/JsonRpcErrorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public JsonRpcErrorFactory(IOptions<JsonRpcServerOptions> options, ILogger<JsonR

/// <inheritdoc />
public IError ParseError(object? errorData) =>
new Error<object>(JsonRpcPreDefinedErrorCodes.ParseError, "Parse error", WrapExceptions(errorData));
new Error<object>(JsonRpcErrorCodes.ParseError, "Parse error", WrapExceptions(errorData));

/// <inheritdoc />
public IError InvalidRequest(object? errorData) =>
new Error<object>(JsonRpcPreDefinedErrorCodes.InvalidRequest, "Invalid Request", WrapExceptions(errorData));
new Error<object>(JsonRpcErrorCodes.InvalidRequest, "Invalid Request", WrapExceptions(errorData));

/// <inheritdoc />
public IError MethodNotFound(object? errorData) =>
new Error<object>(JsonRpcPreDefinedErrorCodes.MethodNotFound, "Method not found", WrapExceptions(errorData));
new Error<object>(JsonRpcErrorCodes.MethodNotFound, "Method not found", WrapExceptions(errorData));

/// <inheritdoc />
public IError InvalidParams(object? errorData) =>
new Error<object>(JsonRpcPreDefinedErrorCodes.InvalidParams, "Invalid params", WrapExceptions(errorData));
new Error<object>(JsonRpcErrorCodes.InvalidParams, "Invalid params", WrapExceptions(errorData));

/// <inheritdoc />
public IError InternalError(object? errorData) =>
new Error<object>(JsonRpcPreDefinedErrorCodes.InternalError, "Internal error", WrapExceptions(errorData));
new Error<object>(JsonRpcErrorCodes.InternalError, "Internal error", WrapExceptions(errorData));

/// <inheritdoc />
public IError ServerError(int code, object? errorData) =>
Expand Down Expand Up @@ -120,11 +120,11 @@ public virtual IError Error(int code, string message, object? errorData) =>
/// </summary>
/// <param name="code">error.code</param>
[ExcludeFromCodeCoverage]
protected static bool IsSpecial(int code) => code is JsonRpcPreDefinedErrorCodes.ParseError
or JsonRpcPreDefinedErrorCodes.InvalidRequest
or JsonRpcPreDefinedErrorCodes.MethodNotFound
or JsonRpcPreDefinedErrorCodes.InvalidParams
or JsonRpcPreDefinedErrorCodes.InternalError;
protected static bool IsSpecial(int code) => code is JsonRpcErrorCodes.ParseError
or JsonRpcErrorCodes.InvalidRequest
or JsonRpcErrorCodes.MethodNotFound
or JsonRpcErrorCodes.InvalidParams
or JsonRpcErrorCodes.InternalError;

/// <summary>
/// Check if code is reserved for server implementation in specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ParseError_WrapException()

var result = errorFactoryMock.Object.ParseError(errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.ParseError, "Parse error", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.ParseError, "Parse error", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand All @@ -56,7 +56,7 @@ public void InvalidRequest_WrapException()

var result = errorFactoryMock.Object.InvalidRequest(errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.InvalidRequest, "Invalid Request", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.InvalidRequest, "Invalid Request", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand All @@ -72,7 +72,7 @@ public void MethodNotFound_WrapException()

var result = errorFactoryMock.Object.MethodNotFound(errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.MethodNotFound, "Method not found", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.MethodNotFound, "Method not found", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand All @@ -88,7 +88,7 @@ public void InvalidParams_WrapException()

var result = errorFactoryMock.Object.InvalidParams(errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.InvalidParams, "Invalid params", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.InvalidParams, "Invalid params", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand All @@ -104,7 +104,7 @@ public void InternalError_WrapException()

var result = errorFactoryMock.Object.InternalError(errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.InternalError, "Internal error", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.InternalError, "Internal error", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public void Exception_JsonRpcMethodNotFoundException_ReturnMethodNotFoundError()

var result = errorFactoryMock.Object.Exception(exception);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.MethodNotFound, "Method not found", new { Method = methodName });
var expected = new Error<object>(JsonRpcErrorCodes.MethodNotFound, "Method not found", new { Method = methodName });
result.Should().BeEquivalentTo(expected);
}

Expand All @@ -241,7 +241,7 @@ public void Exception_JsonRpcFormatException_ReturnInvalidRequestError()

var result = errorFactoryMock.Object.Exception(exception);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.InvalidRequest, "Invalid Request", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.InvalidRequest, "Invalid Request", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand Down Expand Up @@ -274,7 +274,7 @@ public void HttpError_HttpCode400Or422_ReturnInvalidParamsError(int httpCode)

var result = errorFactoryMock.Object.HttpError(httpCode, errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.InvalidParams, "Invalid params", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.InvalidParams, "Invalid params", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand All @@ -291,7 +291,7 @@ public void HttpError_HttpCode401Or403_ReturnMethodNotFoundError(int httpCode)

var result = errorFactoryMock.Object.HttpError(httpCode, errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.MethodNotFound, "Method not found", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.MethodNotFound, "Method not found", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand Down Expand Up @@ -323,7 +323,7 @@ public void HttpError_HttpCode415_ReturnParseError()

var result = errorFactoryMock.Object.HttpError(415, errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.ParseError, "Parse error", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.ParseError, "Parse error", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand All @@ -339,7 +339,7 @@ public void HttpError_HttpCode500_ReturnInternalError()

var result = errorFactoryMock.Object.HttpError(500, errorData);

var expected = new Error<object>(JsonRpcPreDefinedErrorCodes.InternalError, "Internal error", wrappedData);
var expected = new Error<object>(JsonRpcErrorCodes.InternalError, "Internal error", wrappedData);
result.Should().BeEquivalentTo(expected);
errorFactoryMock.Verify();
}
Expand Down

0 comments on commit f80e2bf

Please sign in to comment.