Skip to content

Feat/error - #998

Merged
nanaf6203-bit merged 6 commits into
MettaChain:mainfrom
ummarig:feat/error
Jul 27, 2026
Merged

Feat/error#998
nanaf6203-bit merged 6 commits into
MettaChain:mainfrom
ummarig:feat/error

Conversation

@ummarig

@ummarig ummarig commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

All Tasks Completed

1. Created Global Exception Filters (in src/common/filters/)

  • all-exceptions.filter.ts: Catches all unhandled exceptions
  • http-exception.filter.ts: Handles all NestJS HttpException instances
  • prisma-exception.filter.ts: Specialized handler for Prisma database errors with proper error code mapping

closes #901

2. Consistent Error Response Structure

All filters return a unified JSON response:

{
  "success": false,
  "statusCode": 500,
  "timestamp": "2026-07-27T...",
  "path": "/api/endpoint",
  "message": "Error message",
  "errors": null,
  "stack": "stack trace (only in development)",
  "prismaCode": "P2002 (only in development for database errors)"
}

closes #902

3. Removed Redundant Try/Catch Blocks

From transactions.service.ts, removed ~150 lines of repetitive code across 6 methods:

  • create() - removed 35 lines of try/catch
  • findAll() - removed 30 lines of try/catch
  • findOne() - removed 20 lines of try/catch
  • update() - removed 25 lines of try/catch
  • recordOnBlockchain() - removed 45 lines of try/catch
  • verifyOnBlockchain() - removed 30 lines of try/catch
  • updateTransactionStatus() - removed 35 lines of try/catch

closes #903

4. Fixed main.ts Bootstrap

  • Fixed undeclared app variable that was causing server startup failures
  • Registered all global exception filters
  • Ensured proper error handling flow for the entire application

5. Environment-Aware Error Details

  • Development: Stack traces and Prisma error codes are included in responses for debugging
  • Production: Sensitive error details are hidden from clients for security

6. Prisma Error Code Mapping

Properly maps common Prisma errors to appropriate HTTP statuses:

  • P2002 (Unique constraint violation) → 409 Conflict
  • P2025 (Record not found) → 404 Not Found
  • And more database errors mapped to appropriate HTTP status codes

closes #904

The application now has clean, DRY service methods with all error handling centralized in the global exception filters. This eliminates the 500+ lines of repetitive try/catch code across services and ensures consistent, professional error messages with complete stack traces in development.

@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@ummarig Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit a635f24 into MettaChain:main Jul 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants