Skip to content

Comments

Feature/stellar interceptor system#75

Open
tech-adrian wants to merge 9 commits intoNFTopia-Foundation:mainfrom
tech-adrian:feature/stellar-interceptor-system
Open

Feature/stellar interceptor system#75
tech-adrian wants to merge 9 commits intoNFTopia-Foundation:mainfrom
tech-adrian:feature/stellar-interceptor-system

Conversation

@tech-adrian
Copy link

This PR implements a comprehensive interceptor system for the NFTopia NestJS backend to handle Stellar-specific request and response transformations, Soroban contract error handling, transaction logging, and configurable timeouts.

Closes #67

Changes Proposed

  • Stellar System Configuration: Added src/config/stellar.config.ts to manage environment-specific variables like the RPC URL, network passphrase, and granular timeout configurations for simulations vs. submissions.
  • Custom Error Taxonomy: Introduced domain-specific Stellar errors in src/common/errors/stellar.errors.ts (SorobanRpcError, TransactionFailedError, InsufficientBalanceError, InvalidSignatureError, ContractError).
  • Response Standardization: Added StellarResponseInterceptor to wrap outgoing DTOs in a consistent { data, meta } format, automatically injecting the network context, timestamp, and optional transaction markers.
  • Transaction Logging: Implemented StellarLoggingInterceptor utilizing Nest's logging utilities to trace RPC timings, Soroban contract calls, and general Stellar endpoint usage.
  • Error classification & Masking: Implemented StellarErrorInterceptor to catch our custom StellarError types, map them to standard HTTP exceptions (like 502 Bad Gateway or 400 Bad Request), and automatically redact sensitive secret seeds (starting with S) from error traces.
  • Robust Timeouts: Added StellarTimeoutInterceptor relying on RxJS timeout operators to cancel hanging Soroban streams and simulations based on configurable thresholds.
  • Data Transformation: Added StellarTransformInterceptor to unwrap Horizon pagination cursors correctly and normalize raw Stroops into XLM string decimal formats.
  • Application Wiring: Refactored src/nft/soroban.service.ts to throw the new custom exceptions and globally registered all interceptors and configs within src/main.ts and src/app.module.ts.

Acceptance Criteria Evaluated

  • Stellar response standardization interceptor created.
  • Stellar transaction logging interceptor implemented.
  • Global error handling interceptor created with error classifying.
  • Stellar transaction timeout interceptor added.
  • Stellar account data transformation and pagination unwrapping handled.
  • Timeouts and environments configurable via stellar.config.ts.
  • Secret seeds and sensitive data obfuscated from error messages.

How to Test

  1. Pull the branch feature/stellar-interceptor-system.
  2. Ensure you have your SOROBAN_RPC_URL and STELLAR_NETWORK environment variables set.
  3. Observe standard terminal output for timing metrics when hitting /api/v1/nft routes.
  4. Verify HTTP error statuses when triggering invalid Soroban transactions (mockable via service throws).

@tech-adrian
Copy link
Author

@Oluwaseyi89 please review

@tech-adrian
Copy link
Author

@Oluwaseyi89 please review and merge

@Oluwaseyi89
Copy link
Contributor

@Caxton22 resolve the linting errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a comprehensive interceptor system to handle request/response transformations

2 participants