Skip to content

Commit

Permalink
Add OtherJsonRpcErrorException
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifahmed990 committed Jul 31, 2024
1 parent aec2052 commit 719ecfa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
10 changes: 10 additions & 0 deletions voltaire_bundler/bundle/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class ExecutionException(Exception):
message: str


class OtherJsonRpcErrorCode(Enum):
InternalError = -32603


@dataclass
class OtherJsonRpcErrorException(Exception):
exception_code: OtherJsonRpcErrorCode
message: str


@dataclass
class MethodNotFoundException(Exception):
exception_code: ExecutionExceptionCode
36 changes: 28 additions & 8 deletions voltaire_bundler/execution_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import asyncio
import logging
import traceback
import math
import os
from typing import Any, Optional

from voltaire_bundler.bundle.exceptions import \
ExecutionException, ValidationException, ValidationExceptionCode
ExecutionException, OtherJsonRpcErrorCode, OtherJsonRpcErrorException, ValidationException, ValidationExceptionCode
from voltaire_bundler.cli_manager import ConditionalRpc
from voltaire_bundler.event_bus_manager.endpoint import Client, Endpoint
from voltaire_bundler.typing import Address
from voltaire_bundler.user_operation.user_operation_handler import get_deposit_info
from voltaire_bundler.user_operation.v6.user_operation_v6 import UserOperationV6
from voltaire_bundler.user_operation.v7.user_operation_v7 import UserOperationV7
from voltaire_bundler.user_operation.user_operation import is_user_operation_hash
from voltaire_bundler.user_operation.user_operation_handler import \
get_deposit_info
from voltaire_bundler.user_operation.v6.user_operation_v6 import \
UserOperationV6
from voltaire_bundler.user_operation.v7.user_operation_v7 import \
UserOperationV7
from voltaire_bundler.user_operation.user_operation import \
is_user_operation_hash
from voltaire_bundler.user_operation.v6.user_operation_handler_v6 import \
UserOperationHandlerV6
from voltaire_bundler.user_operation.v7.user_operation_handler_v7 import \
Expand Down Expand Up @@ -638,8 +643,23 @@ async def exception_handler_decorator(
) -> dict:
try:
rpc_call_response = await response_function(rpc_call_request)
return rpc_call_response

except (ExecutionException, ValidationException) as excp:
rpc_call_response = {"payload": excp, "is_error": True}
return rpc_call_response
except ValueError:
rpc_call_response = {
"payload": OtherJsonRpcErrorException(
OtherJsonRpcErrorCode.InternalError,
"Unexpected Error"
),
"is_error": True
}
except Exception:
logging.error(traceback.format_exc())
rpc_call_response = {
"payload": OtherJsonRpcErrorException(
OtherJsonRpcErrorCode.InternalError,
"Unexpected Error"
),
"is_error": True
}
return rpc_call_response

0 comments on commit 719ecfa

Please sign in to comment.