Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_raise(self):
with self.assertRaises(JsonRpcServerError):
raise JsonRpcServerError()
class JsonRpcServerError(Exception):
"""
Base class for the other exceptions.
:param data: Extra info (optional).
"""
message = None
def __init__(self, data=None):
super(JsonRpcServerError, self).__init__(self.message)
# Holds extra information related to the error.
self.data = data
class ParseError(JsonRpcServerError):
"""Raised when the request is not a valid JSON object."""
code = -32700
message = "Parse error"
http_status = status.HTTP_BAD_REQUEST
class InvalidRequest(JsonRpcServerError):
"""
Raised when the request is not a valid JSON-RPC object.
:param data: Extra information about the error that occurred (optional).
"""
code = -32600
message = "Invalid Request"
@bp.app_errorhandler(exceptions.JsonRpcServerError)
def custom_exception_error_handler(exc):
"""Catch any JsonRpcServerError exception, and convert it to
jsonrpc format."""
return flask_error_response(exc.http_status_code, str(exc))
def __init__(self, data=None):
super(JsonRpcServerError, self).__init__(self.message)
# Holds extra information related to the error.
self.data = data
http_status = status.HTTP_NOT_FOUND
class InvalidParams(JsonRpcServerError):
"""
Raised when invalid arguments are passed to a method.
:param data: Extra information about the error that occurred (optional).
"""
code = -32602
message = "Invalid params"
http_status = status.HTTP_BAD_REQUEST
class ServerError(JsonRpcServerError):
"""
Raised when there's an application-specific error on the server side.
:param data: Extra information about the error that occurred (optional).
"""
code = -32000
message = "Server error"
http_status = status.HTTP_INTERNAL_ERROR
http_status=status.HTTP_BAD_REQUEST
)
def response_to_json_query(response):
if check_error_response(response):
response: dict = response['error']
raise GenericJsonRpcServerError(
code=-int(response['code']),
message=response['message'],
http_status=status.HTTP_BAD_REQUEST
)
return response
class GenericJsonRpcServerError(JsonRpcServerError):
"""Raised when the request is not a valid JSON-RPC object.
User can change code and message properly
:param data: Extra information about the error that occurred (optional).
"""
def __init__(self, code: int, message: str, http_status: int, data=None):
"""
:param code: json-rpc error code
:param message: json-rpc error message
:param http_status: http status code
:param data: json-rpc error data (optional)
"""
super().__init__(data)
def __init__(self, data=None):
super(JsonRpcServerError, self).__init__(self.message)
# Holds extra information related to the error.
self.data = data
class ParseError(JsonRpcServerError):
"""Raised when the request is not a valid JSON object."""
code = -32700
message = "Parse error"
http_status = status.HTTP_BAD_REQUEST
class InvalidRequest(JsonRpcServerError):
"""
Raised when the request is not a valid JSON-RPC object.
:param data: Extra information about the error that occurred (optional).
"""
code = -32600
message = "Invalid Request"
http_status = status.HTTP_BAD_REQUEST
class MethodNotFound(JsonRpcServerError):
"""
Raised when the method does not exist/is not available.
:param data: Extra information about the error that occurred (optional).
http_status = status.HTTP_BAD_REQUEST
class MethodNotFound(JsonRpcServerError):
"""
Raised when the method does not exist/is not available.
:param data: Extra information about the error that occurred (optional).
"""
code = -32601
message = "Method not found"
http_status = status.HTTP_NOT_FOUND
class InvalidParams(JsonRpcServerError):
"""
Raised when invalid arguments are passed to a method.
:param data: Extra information about the error that occurred (optional).
"""
code = -32602
message = "Invalid params"
http_status = status.HTTP_BAD_REQUEST
class ServerError(JsonRpcServerError):
"""
Raised when there's an application-specific error on the server side.
:param data: Extra information about the error that occurred (optional).
http_status = status.HTTP_BAD_REQUEST
class InvalidRequest(JsonRpcServerError):
"""
Raised when the request is not a valid JSON-RPC object.
:param data: Extra information about the error that occurred (optional).
"""
code = -32600
message = "Invalid Request"
http_status = status.HTTP_BAD_REQUEST
class MethodNotFound(JsonRpcServerError):
"""
Raised when the method does not exist/is not available.
:param data: Extra information about the error that occurred (optional).
"""
code = -32601
message = "Method not found"
http_status = status.HTTP_NOT_FOUND
class InvalidParams(JsonRpcServerError):
"""
Raised when invalid arguments are passed to a method.
:param data: Extra information about the error that occurred (optional).
# limitations under the License.
from jsonrpcserver.exceptions import JsonRpcServerError
class JsonError:
PARSE_ERROR = -32700
INVALID_REQUEST = -32600
METHOD_NOT_FOUND = -32601
INVALID_PARAMS = -32602
INTERNAL_ERROR = -32603
SERVER_ERROR = -32000
SCORE_ERROR = -32100
class GenericJsonRpcServerError(JsonRpcServerError):
"""Raised when the request is not a valid JSON-RPC object.
User can change code and message properly
:param data: Extra information about the error that occurred (optional).
"""
def __init__(self, code: int, message: str, http_status: int, data=None):
"""
:param code: json-rpc error code
:param message: json-rpc error message
:param http_status: http status code
:param data: json-rpc error data (optional)
"""
super().__init__(data)