BoostryJP / ibet-Prime

Advanced API Toolkit for Digital Securities Issuance and Management on the ibet Network 🚀
https://ibet.jp/ibet-for-fin
Apache License 2.0
11 stars 1 forks source link

[FEATURE] Add exception handling about HTTPError to web3_utils #473

Closed purplesmoke05 closed 1 year ago

purplesmoke05 commented 1 year ago

Is your feature request related to a problem? Please describe.

if a http request is emitted to quorum when quorum get temporary down or so, it will return http status code of 404 and requests.HTTPError like following.

[2023-02-01 12:01:26 + 0000][INDEXER-Personal-Info][161][ERROR] An exception occurred during event synchronization
Traceback(most recent call last):
  File "/app/ibet-Prime/batch/indexer_personal_info.py", line 231, in main
    processor.process()
  File "/app/ibet-Prime/batch/indexer_personal_info.py", line 64, in process
    self.__refresh_personal_info_list(db_session=db_session)
  File "/app/ibet-Prime/batch/indexer_personal_info.py", line 94, in __refresh_personal_info_list
    personal_info_address = ContractUtils.call_function(
  File "/app/ibet-Prime/batch/../app/utils/contract_utils.py", line 155, in call_function
    result=_function(*args).call()
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/contract.py", line 970, in call
    return call_contract_function(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/contract.py", line 1525, in call_contract_function
    return_data=web3.eth.call(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result=w3.manager.request_blocking(method_str,
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/manager.py", line 197, in request_blocking
    response=self._make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/gas_price_strategy.py", line 90, in middleware
    return make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/attrdict.py", line 33, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 87, in middleware
    web3_formatters_builder(w3, method),
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/validation.py", line 140, in build_method_validators
    w3_chain_id=w3.eth.chain_id
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/eth.py", line 632, in chain_id
    return self._chain_id()
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result=w3.manager.request_blocking(method_str,
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/manager.py", line 197, in request_blocking
    response=self._make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/gas_price_strategy.py", line 90, in middleware
    return make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/attrdict.py", line 33, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/buffered_gas_estimate.py", line 40, in middleware
    return make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/formatting.py", line 94, in middleware
    response=make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/middleware/exception_retry_request.py", line 114, in middleware
    return make_request(method, params)
  File "/app/ibet-Prime/batch/../app/utils/web3_utils.py", line 123, in make_request
    return super().make_request(method, params)
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/providers/rpc.py", line 88, in make_request
    raw_response=make_post_request(
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/web3/_utils/request.py", line 103, in make_post_request
    response.raise_for_status()
  File "/home/apl/.pyenv/versions/3.10.4/lib/python3.10/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http: // quorum.local: 8545/

There are no exception handling about HTTPError, so we would like to add it.

https://github.com/BoostryJP/ibet-Prime/blob/015acac7972edcc1ada85392519502d2119b9cad/app/utils/web3_utils.py#L122-L127

Describe the solution you'd like

Add exception handling about HTTPError to web3_utils.