Report a rejected argument as 400 with its reason, not an opaque 500 - #2542
Merged
p-hoffmann merged 1 commit intoAug 30, 2026
Merged
Conversation
The service layer raises IllegalArgumentException for conditions the
caller caused and can act on: a generation, characterization, analysis
or preset named in the request that does not exist. CcServiceImpl alone
does this in eighteen places, each with a message saying exactly what
was not found.
None of it reached the caller. IllegalArgumentException had no handler,
so it fell to the generic fallback, which answers 500 and replaces the
message with the exception's class name. Fetching results for a
characterization whose preset analysis no longer resolves came back as
{"message":"An exception occurred: java.lang.IllegalArgumentException"}
which says neither what was rejected nor that the fault lay with the
request. That is what OHDSI/Atlas3#291 ran into: the reporter could not
tell whether the generation had failed or only the results retrieval,
and had to read the network tab to get even the class name.
Handle it as a 400 carrying the message the service layer already wrote,
and unwrap it when it arrives through a proxy. These messages exist to
be read; everything not raised deliberately still reaches the generic
handler and is still sanitised. An exception with no message at all
falls back to naming its class, which is no worse than before.
Separately, the proxy branch reported the wrapper's own class name
rather than the exception inside it, so an unexpected failure through a
proxy was always described as UndeclaredThrowableException.
Reported in OHDSI/Atlas3#291.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported in OHDSI/Atlas3#291.
Problem
CcServiceImplraisesIllegalArgumentExceptionin eighteen places for conditions the caller caused and can act on, each with a message naming exactly what was not found:None of it reaches the caller.
IllegalArgumentExceptionhas no handler, so it falls to the genericThrowablefallback:A
POST /cohort-characterization/generation/{id}/resultwhose characterization references a preset that no longer resolves therefore answers 500 with{"message":"An exception occurred: java.lang.IllegalArgumentException"}which says neither what was rejected nor that the fault lay with the request. In Atlas3#291 the reporter could not tell whether the generation itself had failed or only the results retrieval, and had to read the network tab to get even the class name.
Change
IllegalArgumentExceptionis handled as 400 carrying the message the service layer already wrote.UndeclaredThrowableException, matching howBadRequestAtlasExceptionandConversionAtlasExceptionare already treated there.On exposure: these messages are written by this codebase for exactly this purpose. Anything not raised deliberately still reaches the generic handler and is still sanitised, and stack traces are still stripped.
Incidental
The proxy branch reported
ex.getClass().getName(), whereexis theUndeclaredThrowableExceptionwrapper rather than the exception inside it, so every unexpected failure arriving through a proxy was described asUndeclaredThrowableException. It now names the real one.Scope
This does not change why a given characterization's results request is rejected; it makes the server say so. Atlas3 side, OHDSI/Atlas3#311 stops the client presenting a rejected results request as an empty table beside a healthy-looking run.
Related precedent: #2539 did the same for tag creation, moving a deliberate rejection off the generic 500 path.
Tests
Four new cases in
GlobalExceptionHandlerTest, all failing before the change:GlobalExceptionHandlerTest: 9 run, 0 failures. The 3VocabularyServiceITfailures in a full run are pre-existing on a clean checkout here (no vocabulary schema available) and unrelated.