From 706b878465416071c3cfed8ff2bac96d7471cbd2 Mon Sep 17 00:00:00 2001 From: Arda Nakisci Date: Tue, 24 Feb 2026 15:32:39 +0300 Subject: [PATCH] fix: return preflight errors as 400 instead of generic 500 PreflightError (e.g. "ERC20: transfer amount exceeds balance") was falling through to the catch-all arm in map_raindex_error and being returned as a 500 Internal Error with a generic message. Now it is explicitly matched and returned as a 400 Bad Request with the readable error message so callers know why their swap failed. Also export COMMIT_SHA automatically in the nix dev shell so local cargo builds no longer need the env var set manually. Add dev-config.toml and gitignore docs/book/ build output. --- .gitignore | 1 + dev-config.toml | 6 ++++++ flake.nix | 4 +++- src/routes/swap/mod.rs | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 dev-config.toml diff --git a/.gitignore b/.gitignore index 73640bd..7ae1d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ logs/ data/* !data/.gitkeep +docs/book/ diff --git a/dev-config.toml b/dev-config.toml new file mode 100644 index 0000000..6dd1674 --- /dev/null +++ b/dev-config.toml @@ -0,0 +1,6 @@ +log_dir = "/tmp/st0x-logs" +database_url = "sqlite:///tmp/st0x-dev.db" +registry_url = "https://raw.githubusercontent.com/rainlanguage/rain.strategies/aeaf8d5eaac90b08fe01b9a5d69089d1a0cc1a8f/registry" +rate_limit_global_rpm = 1000 +rate_limit_per_key_rpm = 100 +docs_dir = "docs/book" diff --git a/flake.nix b/flake.nix index c03cdc2..417ed40 100644 --- a/flake.nix +++ b/flake.nix @@ -167,7 +167,9 @@ devShells.default = pkgs.mkShell { inherit (rainix.devShells.${system}.default) nativeBuildInputs; - inherit (rainix.devShells.${system}.default) shellHook; + shellHook = rainix.devShells.${system}.default.shellHook + '' + export COMMIT_SHA="$(git rev-parse HEAD 2>/dev/null || echo "dev")" + ''; buildInputs = with pkgs; [ sqlx-cli diff --git a/src/routes/swap/mod.rs b/src/routes/swap/mod.rs index 2cffbce..e0db8bb 100644 --- a/src/routes/swap/mod.rs +++ b/src/routes/swap/mod.rs @@ -138,6 +138,10 @@ fn map_raindex_error(e: RaindexError) -> ApiError { tracing::warn!(error = %e, "invalid request parameters"); ApiError::BadRequest(e.to_string()) } + RaindexError::PreflightError(_) => { + tracing::warn!(error = %e, "preflight simulation failed"); + ApiError::BadRequest(e.to_readable_msg()) + } _ => { tracing::error!(error = %e, "calldata generation failed"); ApiError::Internal("failed to generate calldata".into())