From 0a13602e35fbfbb1abbdf7cefc33b2894754b199 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 30 Mar 2024 23:19:33 +0400 Subject: [PATCH] fix(api): Change error code for Web3Error::NotImplemented (#1521) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Changes the error code for `Web3Error::NotImplemented` from `InternalError` to `MethodNotFound`. ## Why ❔ Better representation of the nature of an error. Useful for better error-handling on the client side. ## Checklist - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`. --- .../zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs | 5 ++--- core/lib/zksync_core/src/api_server/web3/tests/filters.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs index 1cd93b51830..ec9228b1521 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/mod.rs @@ -29,9 +29,8 @@ impl MethodTracer { _ => None, }; let code = match err { - Web3Error::InternalError(_) | Web3Error::NotImplemented => { - ErrorCode::InternalError.code() - } + Web3Error::NotImplemented => ErrorCode::MethodNotFound.code(), + Web3Error::InternalError(_) => ErrorCode::InternalError.code(), Web3Error::NoBlock | Web3Error::PrunedBlock(_) | Web3Error::PrunedL1Batch(_) diff --git a/core/lib/zksync_core/src/api_server/web3/tests/filters.rs b/core/lib/zksync_core/src/api_server/web3/tests/filters.rs index 93e44f3f473..09944cec6fd 100644 --- a/core/lib/zksync_core/src/api_server/web3/tests/filters.rs +++ b/core/lib/zksync_core/src/api_server/web3/tests/filters.rs @@ -269,7 +269,7 @@ async fn log_filter_changes_with_block_boundaries() { fn assert_not_implemented(result: Result) { assert_matches!(result, Err(Error::Call(e)) => { - assert_eq!(e.code(), ErrorCode::InternalError.code()); + assert_eq!(e.code(), ErrorCode::MethodNotFound.code()); assert_eq!(e.message(), "Not implemented"); }); }