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.
| Input | HTTP |
|---|---|
HttpException | Its status |
BadRequestException with an array | 400. Translated messages in the body only when debug is on |
| Any other throw | 500, generic internal error message |
| Status >= 500 | Logged and sent to Sentry through reportError |
Validation pipe failures are 400 before the controller runs. Unknown properties are rejected.
Where the row stands
| Failure | Business row | Retry |
|---|---|---|
Throw inside prisma.$transaction before commit | Rolled back, including the outbox insert | The client or scheduler must retry the original operation |
| Outbox consumer throws | Already committed | Dispatcher retries that event, max 10, then DEAD. Sentry on the first failure and on DEAD |
| Bull job throws | Depends on the job. Many jobs mutate before they throw | Queue attempts, then a retained failed job and Sentry on the terminal attempt |
@OnLocalEvent listener throws | Producer already committed | Nothing retries. Reported to Sentry |
| Local emit with no listener | Producer already committed | Nothing 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:
| Situation | Do |
|---|---|
The caller, TrackedCron, Bull or the outbox can handle it | Rethrow, or do not catch |
| One item in a loop, or a best-effort step after the main write | Log, 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
| System | Observed behavior |
|---|---|
| Marketplace sync | Bull retries (3), then the circuit breaker sets the channel to SUSPENDED |
| Inventory publish | Queue retry, per-item success: false, feed poll reaper for async feeds |
| Courier label | Fulfillment can sit in LABEL_CREATION_FAILED and move back to LABEL_CREATING |
| S3 | Boot fails if required settings are missing. Runtime S3 errors were not catalogued |
| SMTP | Email job retries. Forgot-password still returns success to the client |
| AI gateway | Boot continues. Embeddings degrade. Workspace routes 403 until AI_WORKSPACE_ENABLED=true |
| Bharat Address | The address job fails and retries if the processor throws. Fallback address status is unknown |
| Unknown channel type | Scheduler 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
$transactionis 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:
WalletListeneris a non-transactional consumer, so a retry can call the debit again. The ledger entry carries idempotency keyorder-token-deduction:<orderId>andpostEntryreturns the existing entry for a repeated key, so the second call does not debit.- Two copies of the order state machine. They match today.
isValidOrderTransitionreturns true when the current status is null, which allows any initial status.return.status.changedandreturn.stock.restoredhave no listener.StockMovementuniqueness includescreatedAt.- Midnight cron only logs. Other schedulers no longer catch their whole run, so a failed run reaches
TrackedCronand Sentry. - Courier seed codes
NIP,PIK,SHYP,ARMX,AMZhave no strategy class. - Refresh-token is public and relies on
JwtRefreshGuardonly. - Permissions default to allow when the decorator is omitted.
- Raw SQL bypasses the tenancy extension unless the SQL filters
tenantId. /metricsis unauthenticated in the application. Network policy is unknown.- 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.