You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "priyam99 (via GitHub)" <gi...@apache.org> on 2026/10/11 18:46:46 UTC
[PR] Return HTTP 409 for invalid loan application state transitions [fineract-loan-origination]
priyam99 opened a new pull request, #169:
URL: https://github.com/apache/fineract-loan-origination/pull/169
## Description
Invalid loan lifecycle actions returned `500 Internal Server Error` instead of `409 Conflict`.
`LoanOriginationStateMachine.transition()` throws `LoanStateTransitionException` when a transition is not allowed (for example, submitting an `APPROVED` application). `GlobalExceptionHandler` had no handler for it, so it fell through to the generic `Exception` handler and was reported as a server error. The REST API docs (`docs/api/rest-api.adoc`) and the backend architecture doc already specify `409` for invalid transitions.
This PR adds a `LoanStateTransitionException` handler that returns `409 Conflict` with the standard `ErrorResponse` (`status`, `error`, `message`, `timestamp`), next to the existing `409` handlers. No other behaviour changes. Terminal-state attempts already returned `409` through the existing `IllegalStateException` handler and are unaffected.
Closes #162
## Verification
- [x] `./mvnw spotless:apply`
- [x] `./mvnw clean verify`: build succeeds. 190 unit tests (including the 4 new ones) and 7 Cucumber integration tests (Testcontainers PostgreSQL) pass with 0 failures, and the Spotless check passes.
- [x] `./mvnw apache-rat:check`
- [x] Frontend changes: not applicable, because there are no frontend changes.
New tests:
- `GlobalExceptionHandlerTest`: `LoanStateTransitionException` maps to `409` with the transition message.
- `LoanApplicationControllerTest` (MockMvc with the real service and state machine, mocked repositories):
- `APPROVED` → submit returns `409`, the status stays `APPROVED`, and nothing is saved.
- `DRAFT` → start-review returns `409`, the status stays `DRAFT`, and credit scoring is not triggered.
- `DRAFT` → submit still returns `200` with status `SUBMITTED`.
I also confirmed the two `409` tests fail with `500` when the new handler is removed.
## AI assistance (optional)
- Tool / model: Claude Code (Claude Opus 5.5)
- How it was used: traced the exception path, drafted the handler and tests, and ran the checks. I reviewed every line.
## Checklist
- [x] This PR is one logical change, not a code dump.
- [x] I added or updated tests, or explained why tests are not needed.
- [x] New files carry the ASF license header.
- [x] Docs (and `AGENTS.md`, if commands, paths, or architecture rules changed) are updated. (No doc change needed; the docs already specify `409`.)
- [x] All commits are signed.
- [x] I followed the [AI Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy) and the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Return HTTP 409 for invalid loan application state transitions [fineract-loan-origination]
Posted by "KRYSTALM7 (via GitHub)" <gi...@apache.org>.
KRYSTALM7 commented on code in PR #169:
URL: https://github.com/apache/fineract-loan-origination/pull/169#discussion_r4246817739
##########
src/main/java/org/apache/fineract/los/exception/GlobalExceptionHandler.java:
##########
Review Comment:
Thanks for adding tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Return HTTP 409 for invalid loan application state transitions [fineract-loan-origination]
Posted by "KRYSTALM7 (via GitHub)" <gi...@apache.org>.
KRYSTALM7 commented on PR #169:
URL: https://github.com/apache/fineract-loan-origination/pull/169#issuecomment-6122613046
Good job @priyam99! The description is clean and easy to follow.
Leaving the terminal states (REJECTED, DISBURSED) on the IllegalStateException handler is the right call, and the sanity check of removing the handler to see the tests fail with 500 is a nice touch.
Partially approved from my side. @Aman-Mittal once we get the curl command output or image, I think we can merge this.
@priyam99 also, please join the dev mailing list or the Matrix channel so you can DM us directly whenever a review is needed on your PRs. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Return HTTP 409 for invalid loan application state transitions [fineract-loan-origination]
Posted by "Aman-Mittal (via GitHub)" <gi...@apache.org>.
Aman-Mittal merged PR #169:
URL: https://github.com/apache/fineract-loan-origination/pull/169
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org