Skip to content

fix(api): enforce HTTP status semantics for login/session endpoints#168

Open
VarshiniGunti wants to merge 1 commit into
PSMRI:mainfrom
VarshiniGunti:issue-114-api-status-codes
Open

fix(api): enforce HTTP status semantics for login/session endpoints#168
VarshiniGunti wants to merge 1 commit into
PSMRI:mainfrom
VarshiniGunti:issue-114-api-status-codes

Conversation

@VarshiniGunti
Copy link
Copy Markdown

📋 Description

JIRA ID: N/A (GitHub issue PSMRI/AMRIT#114)

This PR starts the MMU-API side of HTTP status code correction for login/session-related endpoints and introduces centralized exception handling with a standard error response structure.

What changed

  1. Centralized exception handling
  • Added global exception handler using @ControllerAdvice:
    • GlobalExceptionHandler
  • Added standardized error payload model:
    • ApiErrorResponse with timestamp, statusCode, error, errorMessage, path
  1. Login/session controller status code alignment
  • Updated IemrMmuLoginController endpoints to return ResponseEntity<String> with explicit HTTP status codes instead of always returning a 200-style body.
  • Applied explicit status handling:
    • 200 for success
    • 400 for invalid request payload/parameters
    • 401 for missing/invalid auth token
    • 404 for not found scenarios (getVanMaster)
    • 500 for internal server errors
  1. Swagger/OpenAPI response alignment
  • Added @ApiResponses annotations on updated endpoints to reflect expected HTTP responses (200/400/401/404/500), improving API contract clarity for consumers.

Motivation

Issue #114 highlights that APIs were often returning success semantics even for failure scenarios, making UI handling and debugging difficult.
This PR improves REST compliance and creates a reusable exception/status pattern that can be extended across additional controllers in follow-up work.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Validation performed

  • Ran compile check successfully:
    • mvn -DskipTests compile
  • Confirmed the build succeeds with this change set.
  • Existing project-wide checkstyle warnings are present in the repo baseline and are not introduced by this PR.

Notes

  • This is the backend/API part of #114 and is designed to pair with the MMU-UI PR that updates UI error handling for 4xx/5xx responses.
  • Scope is intentionally focused on login/session-related endpoints and centralized exception foundation to keep the PR mergeable and safe.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Warning

Rate limit exceeded

@VarshiniGunti has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 43 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 261143c0-5938-49e0-b3a8-df5f776d50d0

📥 Commits

Reviewing files that changed from the base of the PR and between 2a87f0d and 2846f34.

📒 Files selected for processing (3)
  • src/main/java/com/iemr/mmu/controller/login/IemrMmuLoginController.java
  • src/main/java/com/iemr/mmu/utils/exception/ApiErrorResponse.java
  • src/main/java/com/iemr/mmu/utils/exception/GlobalExceptionHandler.java
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

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