Skip to content

Enhance Hero Error Handling with Custom Error Classes#1

Open
xLDVx wants to merge 4 commits into
TheRealB9:67aa43ad-be87-427c-a430-fc792a400a96from
xLDVx:feat-hero-custom-error-classes-1749254331
Open

Enhance Hero Error Handling with Custom Error Classes#1
xLDVx wants to merge 4 commits into
TheRealB9:67aa43ad-be87-427c-a430-fc792a400a96from
xLDVx:feat-hero-custom-error-classes-1749254331

Conversation

@xLDVx
Copy link
Copy Markdown

@xLDVx xLDVx commented Jun 6, 2025

Enhance Hero Error Handling with Custom Error Classes

Description

Task

Create custom error classes for hero-specific errors

Acceptance Criteria

  • Create base HeroError class
  • Implement HeroNotFoundError with dynamic hero name
  • Add InvalidHeroDataError with validation reason
  • Create UnauthorizedHeroAccessError
  • Ensure all errors provide clear, informative messages

Summary of Work

Custom Hero Error Classes Implementation

Changes Made

  • Expanded custom error classes in src/errors/hero-errors.ts
  • Implemented a robust hierarchy of hero-specific error classes
  • Added comprehensive error messaging for different scenarios

Error Classes Overview

  1. HeroError: Base class for all hero-related errors

    • Provides a consistent error naming and handling mechanism
    • Allows for centralized error management
  2. HeroNotFoundError: Specific error for missing heroes

    • Dynamically includes the hero name in the error message
    • Helps identify exactly which hero was not found
  3. InvalidHeroDataError: Error for data validation issues

    • Provides detailed reason for data invalidity
    • Supports granular error reporting for data inconsistencies
  4. UnauthorizedHeroAccessError: Error for access control scenarios

    • Generic unauthorized access error for hero resources
    • Supports security and permission-based error handling

Implementation Details

  • Used TypeScript for type-safe error definitions
  • Maintained a clear inheritance hierarchy
  • Ensured each error has a unique, descriptive name
  • Implemented constructor methods with meaningful error messages

Testing Approach

  • Existing test file src/errors/hero-errors.test.ts covers error class instantiation
  • Verified error message generation
  • Confirmed proper error inheritance and naming

Benefits

  • More precise error handling
  • Improved debugging capabilities
  • Clear separation of error types
  • Enhanced API error responses

Potential Future Improvements

  • Add more specific error subclasses as needed
  • Implement error logging mechanism
  • Create centralized error handling middleware

Changes Made

  • Expanded base HeroError class
  • Added HeroNotFoundError for missing heroes
  • Implemented InvalidHeroDataError for data validation
  • Created UnauthorizedHeroAccessError for access control

Tests

  • Verify HeroNotFoundError includes correct hero name
  • Confirm InvalidHeroDataError captures specific validation reason
  • Ensure UnauthorizedHeroAccessError has correct message
  • Check inheritance of all custom errors from base HeroError

Signatures

Staking Key

He88p8gayqrGSWqpj7Mu4XzqcKsURDjnuK1z2UMnio3A: 3PQSgKNGffAxeQcPJP1XoDFCe3FUv5wqm5sTjGBiFiQjVo1jH4hsxuc2otErK5nbiE2pNTDwQ6icgznX3j6wYptGRHi32gyu6Yh9Jp9YmdHtdo8jsEvG6bEHuSbkxNdYMnUZdETqiLNYoViG6QiW2WhkUBJtS37b1HYpegaZp326NXqQHNfeSgZCFwSyhLcWWmgLLrJQUcYCjof1ZC3dyZrpJcVsuuAnWirUTppkXg1T5zh1sJKrhURh8kYf4gJVCzmJeh72rG9NnFQtyBrvks336Lw6CPRXYScRW2u2uVnqz65Cko1SyxJhCNLKDHVRqMNMqsEvPPPEP2T2ny3STuntiCsekw9VMUFMVwonq3mdxsXPPQDtBG2qp9aBkyTzyQVyL7AuxkxxeSg1XAzi3Cw3Cdz

Public Key

FVeknmSZKTCvd8fxFxt5T4mQgxED2QhYBZyexLyCrrB8: F9mEKhsjGDHFdZ5agYC9dds78vvCJPq2u6NAYGSr69R8PusUdJejscqBoQdsftJ5eEm6WZMF5BpV746wuuiWKcbn2M4XJcAFFodZxXCdpz9PPDSVmSYgrxQ8NNKF7jAkNPJDzoJtZ4GAhk1nKX1zqfZkuZvkGCgSay3Np6pd8zhBs6kUyGnL8nFcTj9d9nnGyszNDkLFwkko1g4jxo4EiExAk4LMkDruGGtJB4c1b5aGVhRPqsqjhrPN2efVEhAVmqpqEo6i1EzSwKqHB2TKA1QXGLLL6ubPtw1UF7mcczKV7vQX3CDR95WQu5kASg9aMYmRKT7H6Y6RbjiemesDaki8q3AFDuz7QoJY1EUYw3GNSeGCwHifyvWiLdxadAeDvb5RNcp9ectt5i4sNXkjG23ssKJ

@xLDVx xLDVx changed the title [WIP] Implement Custom Error Classes for Hero API Error Handling Enhance Hero Error Handling with Custom Error Classes Jun 7, 2025
@xLDVx xLDVx marked this pull request as ready for review June 7, 2025 00:01
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.

1 participant