Client/Server Exception and Success Mapping for Adventuretube Microservice

In a well-designed microservice system, exception and success classification must be consistent, traceable, and informative. Below is a complete reference list organized by type and mapped to HTTP status codes. Each exception or success type reflects its purpose: successful operations (2xx), client errors (4xx), or server errors (5xx).


✅ 1. Success Response Types → HTTP 2xx

IdentifierMeaningHTTP Code
UserRegisteredSuccessfullyNew user was created successfully201
LoginSuccessLogin completed and tokens issued200
LogoutSuccessToken revoked/logged out200
TokenRefreshedAccess/refresh tokens issued200
TokenStoredToken saved successfully200
TokenDeletedToken deleted successfully200
UserDeletedUser account removed successfully200
EmailAvailableEmail is free for registration200
ProfileUpdatedProfile details updated200

⚠️ 2. Domain-Specific Exceptions → HTTP 4xx

(Client-side problems: validation, auth, bad data)

Exception ClassMeaningHTTP Code
UserNotFoundExceptionUser ID/email not found404
DuplicateExceptionEmail already exists during registration409
TokenExpiredExceptionToken provided by client has expired401
InvalidTokenExceptionToken format or signature is invalid401
InvalidInputFormatExceptionRequest body malformed or fails validation400
InvalidEmailFormatExceptionEmail does not follow pattern400
UnsupportedMediaTypeExceptionRequest content-type not accepted415
GoogleIdTokenInvalidExceptionGoogle token invalid or does not match expected user401

💥 3. Domain-Specific Exceptions → HTTP 5xx

(Server-side failures: internal, upstream, logic failure)

Exception ClassMeaningHTTP Code
TokenSaveFailedExceptionFailed to store token in DB500
MemberServiceExceptionFailed when calling member microservice500
TokenDeletionExceptionFailed to revoke/delete token500
TokenNotFoundExceptionUnexpected error fetching token500
ServiceDependencyFailureExceptionUpstream service returned error or timeout503
JwtGenerationExceptionFailed to generate JWT token500
UnknownServerErrorExceptionFallback for unhandled RuntimeExceptions500

✅ Priority Order for Exception Handling in createUser

1. 🛠️ MemberServiceException (Dependency Failure)

  • Why first?
    If the member-service is unavailable, unreachable, or throws a 5xx error,
    there’s no point in validating domain rules — nothing else can proceed.

  • Examples: service down, timeout, internal error in member-service.

  • HTTP: 500

2. 🔐 Domain-Specific 4xx Errors (Client Validation & Business Rules)

  • Why second?
    Once the member-service responds successfully, domain rules must be
    enforced (e.g., duplicate email, invalid tokens).

  • Handled by: your own microservice logic or parsed from the response body.

  • Examples:

    • DuplicateException

    • GoogleIdTokenInvalidException

    • InvalidEmailFormatException

  • HTTP: 400–409

3. 🧨 UnknownServerErrorException or generic RuntimeException

  • Why last?
    This is a fallback for logic bugs or uncaught exceptions. It ensures you never
    expose stack traces or generic error messages to the client.

  • Handled by: global @ControllerAdvice

  • HTTP: 500


🔁 Flow Visualization

verifyGoogleToken()
  ↓
call member-service (email check / register)
  ↓
| If fails → MemberServiceException |
  ↓
validate duplication, Google token match
  ↓
| If fails → Domain-specific 4xx errors |
  ↓
proceed to token issuance/storage
  ↓
| If fails → TokenSaveFailedException or UnknownServerErrorException |
  ↓
return 201 Created with tokens

![createUser Exception Flow](sandbox:/mnt/data/Screenshot 2025-06-16 at 9.54.47 pm.png)

Let me know if you want to:

  • Add controller advice mappings for these

  • Convert this into an enum/error registry system

  • Integrate this with Swagger OpenAPI annotations

  • Map each exception with a unique error code (e.g., M101, A203)

Leave a Comment

Your email address will not be published. Required fields are marked *