Skip to content

Latest commit

 

History

History
72 lines (60 loc) · 1.34 KB

File metadata and controls

72 lines (60 loc) · 1.34 KB

Error Handling

Error Structure

{
  success: false,
  error: {
    code: string,
    message: string,
    statusCode: number,
    timestamp: string,
    path: string,
    details?: any
  }
}

Error Codes

Format

  • Code: MODULE_ACTION_ERROR
  • Examples: AUTH_INVALID_SIGNATURE, LOAN_NOT_FOUND, BLOCKCHAIN_TX_FAILED

Categories

  • AUTH_*: Authentication errors
  • VALIDATION_*: Validation errors
  • NOT_FOUND_*: Resources not found
  • BLOCKCHAIN_*: Blockchain errors
  • DATABASE_*: Database errors
  • EXTERNAL_*: External service errors

NestJS Exceptions

BadRequestException (400)

throw new BadRequestException({
  code: 'VALIDATION_INVALID_INPUT',
  message: 'Invalid input provided'
});

UnauthorizedException (401)

throw new UnauthorizedException({
  code: 'AUTH_INVALID_TOKEN',
  message: 'Invalid or expired token'
});

NotFoundException (404)

throw new NotFoundException({
  code: 'LOAN_NOT_FOUND',
  message: 'Loan not found'
});

InternalServerErrorException (500)

throw new InternalServerErrorException({
  code: 'DATABASE_CONNECTION_ERROR',
  message: 'Database connection failed'
});

Exception Filter

  • Centralize error formatting
  • Automatic logging
  • HTTP status code mapping
  • Hide internal details in production