Skip to main content

Error handling

ResponseExceptionFilter (@Catch()) translates throws. Messages go through MessageService (i18n key or default). Debug stacks and validation arrays are included only when app.debug is true.

InputHTTP
HttpExceptionIts status
BadRequestException with an array400. Translated messages in the body only when debug is on
Any other throw500, generic internal error message
Status >= 500Logged and sent to Sentry through reportError

Validation pipe failures are 400 before the controller runs. Unknown properties are rejected.

Where the row stands​

FailureBusiness rowRetry
Throw inside prisma.$transaction before commitRolled back, including the outbox insertThe client or scheduler must retry the original operation
Outbox consumer throwsAlready committedDispatcher retries that event, max 10, then DEAD. Sentry on the first failure and on DEAD
Bull job throwsDepends on the job. Many jobs mutate before they throwQueue attempts, then a retained failed job and Sentry on the terminal attempt
@OnLocalEvent listener throwsProducer already committedNothing retries. Reported to Sentry
Local emit with no listenerProducer already committedNothing retries

Each outbox consumer has its own ProcessedEvent record, so on retry only the consumers that failed run again. See Async processing.

Reporting to Sentry​

Everything goes through reportError(error, { component, tags }) in src/common/observability/report-error.ts. It tags the tenant, actor and correlation id from the request context, and never throws. No other file imports @sentry/*; yarn architecture:check enforces it.

A catch block does one of three things:

SituationDo
The caller, TrackedCron, Bull or the outbox can handle itRethrow, or do not catch
One item in a loop, or a best-effort step after the main writeLog, call reportError, continue
A failure that is not a bug (store down, invalid user input)Log a warning, or throw ExpectedError / TransientIntegrationError, which reportError records as a breadcrumb

Logging at error level and continuing is rejected by yarn architecture:check. A catch around a whole cron run or queue job is the case to avoid most: it hides the failure from TrackedCron and Bull, which already report.

External systems​

SystemObserved behavior
Marketplace syncBull retries (3), then the circuit breaker sets the channel to SUSPENDED
Inventory publishQueue retry, per-item success: false, feed poll reaper for async feeds
Courier labelFulfillment can sit in LABEL_CREATION_FAILED and move back to LABEL_CREATING
S3Boot fails if required settings are missing. Runtime S3 errors were not catalogued
SMTPEmail job retries. Forgot-password still returns success to the client
AI gatewayBoot continues. Embeddings degrade. Workspace routes 403 until AI_WORKSPACE_ENABLED=true
Bharat AddressThe address job fails and retries if the processor throws. Fallback address status is unknown
Unknown channel typeScheduler logs a warning and continues. That channel is not synced

Circuit breaker in sync-job.processor.ts: 5 consecutive non-transient failures of one sync type inside 6 hours suspend the channel. Auth-shaped failures suspend after 2 inside that window. The comment says auth-shaped failures still need corroboration. Read evaluateCircuitBreaker before you describe the exact error classes. Jobs still retry inside Bull before that history accumulates.

Partial success​

  • A single aggregate inside one $transaction is atomic.
  • Outbox plus aggregate is atomic only when enqueue uses the same tx.
  • Label purchase at a courier is not in the same transaction as the database. A crash after the courier accepts and before the local commit can leave an external shipment with no local row, or the reverse. Compensating cancel was not verified per carrier.
  • Bulk inventory publish returns per-item results. A chunk can contain both successes and failures.
  • Settlement import can record a batch status while individual lines fail. Line-level commit rules are unknown.

Known risks​

Documented as behavior, not as a fix:

  1. WalletListener is a non-transactional consumer, so a retry can call the debit again. The ledger entry carries idempotency key order-token-deduction:<orderId> and postEntry returns the existing entry for a repeated key, so the second call does not debit.
  2. Two copies of the order state machine. They match today.
  3. isValidOrderTransition returns true when the current status is null, which allows any initial status.
  4. return.status.changed and return.stock.restored have no listener.
  5. StockMovement uniqueness includes createdAt.
  6. Midnight cron only logs. Other schedulers no longer catch their whole run, so a failed run reaches TrackedCron and Sentry.
  7. Courier seed codes NIP, PIK, SHYP, ARMX, AMZ have no strategy class.
  8. Refresh-token is public and relies on JwtRefreshGuard only.
  9. Permissions default to allow when the decorator is omitted.
  10. Raw SQL bypasses the tenancy extension unless the SQL filters tenantId.
  11. /metrics is unauthenticated in the application. Network policy is unknown.
  12. MCP and OAuth routes write OAuth/JSON-RPC error bodies themselves and bypass the response envelope and exception filter.

Courier services, especially Shiprocket, contain many catch blocks. Several update local shipment state or enqueue a webhook from inside the catch. Do not describe a carrier call as one transaction with the local database.

HTTP development guide: Validation and errors.