refactor: standardize HTTP error handling across connectors#564
refactor: standardize HTTP error handling across connectors#564fengtality merged 7 commits intodevelopmentfrom
Conversation
Add httpErrors service for standardized HTTP error responses without requiring FastifyInstance parameter in connector functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace fastify.httpErrors with centralized httpErrors service and remove FastifyInstance parameter from connector functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Update test files to match new function signatures without FastifyInstance parameter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
ff8bfd9 to
09d25be
Compare
Remove helius and infura namespace references from root.yml since the rpc-provider-schema.json and rpc/ directory were previously removed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Commit a9b8f7a
Manual API Tests - Error Responses
Manual API Tests - Rate Limiting (429)
Pending
incase needed, attach test and gateway logs: 12052025a.zip |
Manual API Tests - Error Responses400 bad request
404 not found
500 internal server error
Manual API Tests - Rate Limiting (429)
|
|
- Add proper httpErrors (400/404) instead of 500 for validation errors - Add address validation in connector methods (Orca, Raydium, Meteora, PancakeSwap-Sol) - Add `if (e.statusCode) throw e;` pattern to re-throw HttpErrors in route handlers - Fix ConfigManagerV2 to throw proper httpErrors for schema violations - Add validation error logging in app.ts global error handler - Update tests for new error behavior Routes fixed: - All Raydium AMM routes (executeSwap, quoteLiquidity, removeLiquidity, addLiquidity, positionInfo) - All Raydium CLMM routes (removeLiquidity, addLiquidity, quotePosition, poolInfo, positionInfo, collectFees) - Meteora CLMM routes (quotePosition, positionInfo, etc.) - Orca CLMM routes (poolInfo, positionInfo, positionsOwned) Connector methods updated: - meteora.ts: getPositionInfoByAddress(), getPositionInfo() - orca.ts: getPositionInfo() - raydium.ts: getPositionInfo() - pancakeswap-sol.ts: getPositionInfo() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Commit a4d8a89
400 Bad Request ✅
404 Not Found
500 Internal Server Error
|

Summary
httpErrorshelper instead offastify.httpErrorsfastifyparameter from connector route functions where only used for error handlingHttpErrorclass and helper functions insrc/services/error-handler.tswalletAddressoptional for router swap quotes (uses placeholder address)Changes
New Error Handler Service (
src/services/error-handler.ts)HttpErrorclass with proper statusCode and error name mappingbadRequest,notFound,internalServerError,serviceUnavailable,forbiddenhttpErrorsobject as drop-in replacement forfastify.httpErrorscreateErrorfunction for custom status codes (400, 401, 403, 404, 409, 429, 500, 502, 503)Connector Refactoring
fastifyparameter from ~70 connector route functionsfastify.httpErrors.*calls withhttpErrors.*from error-handler serviceTrading Routes Simplification
fastifyparameter from trading route handlerssrc/trading/swap/quote.tsandsrc/trading/swap/execute.tsRouter Swap Quote Fix
walletAddressoptional for Uniswap/PancakeSwap router quotesTest Plan
Automated Tests
pnpm test- all 91 test suites should pass (774 tests)pnpm typecheck- no TypeScript errorsManual API Tests - Error Responses
400 Bad Request
GET /trading/swap/quote?chainNetwork=invalidreturns 400 with proper error formatPOST /connectors/uniswap/clmm/open-positionwith missing required fields returns 400404 Not Found
GET /trading/swap/quote?chainNetwork=solana-mainnet-beta&baseToken=INVALIDTOKEN"eToken=USDCreturns 404 for unknown tokenGET /connectors/raydium/clmm/pool-info?network=mainnet-beta&poolAddress=invalidreturns 404500 Internal Server Error
{"statusCode": 500, "error": "HttpError", "message": "..."}Manual API Tests - Rate Limiting (429)
Repeatedly call these endpoints until 429 Too Many Requests is returned to verify rate limit error handling:
GET /chains/solana/balances?network=mainnet-beta&address=<wallet>- repeat until 429GET /chains/ethereum/allowances?network=mainnet&address=<wallet>&tokenSymbols=USDC&spender=<spender>- repeat until 429GET /trading/swap/quote?chainNetwork=solana-mainnet-beta&connector=jupiter/router&baseToken=SOL"eToken=USDC&amount=1&side=SELL- repeat until 429Expected: 429 response returns
{"statusCode": 429, "error": "HttpError", "message": "Rate limit exceeded..."}Manual API Tests - Swap Quotes (without wallet)
Uniswap Router Quote
GET /trading/swap/quote?chainNetwork=ethereum-base&connector=uniswap/router&baseToken=WETH"eToken=USDC&amount=1&side=SELLreturns quote without requiring walletAddressPancakeSwap Router Quote
GET /trading/swap/quote?chainNetwork=ethereum-bsc&connector=pancakeswap/router&baseToken=WBNB"eToken=USDC&amount=1&side=SELLreturns quote without requiring walletAddressManual API Tests - Swap Execution
Solana Swaps
Ethereum Swaps
Error Format Verification
{"statusCode": <code>, "error": "HttpError", "message": "<message>"}🤖 Generated with Claude Code