SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error#4183
Open
gerlowskija wants to merge 3 commits intoapache:mainfrom
Open
SOLR-17549: v2 SolrRequest/SolrResponse should throw exception on error#4183gerlowskija wants to merge 3 commits intoapache:mainfrom
gerlowskija wants to merge 3 commits intoapache:mainfrom
Conversation
Prior to this commit our generated v2 SolrRequest implementations only reported errors in the POJO itself. A failure response from Solr wouldn't trigger a RemoteSolrException as SolrJ users are used to with our v1 APIs. Error detection in our SolrClient implementations attempted to detect-and-throw in these v2 cases, but that detection was keying off of a 'NamedList' key that wasn't being populated by JacksonDatabindResponseParser (which is used for these v2 SolrRequest/Response pairs). This commit updates JacksonDatabindResponseParser to populate this "error" key that SolrClient's were looking for.
epugh
approved these changes
Mar 3, 2026
Contributor
epugh
left a comment
There was a problem hiding this comment.
LGTM with two small comments... This is exciting!
| } | ||
|
|
||
| private void assertRSECodeAndMessage( | ||
| RemoteSolrException rse, int expectedCode, String... expectedMessagePices) { |
Contributor
There was a problem hiding this comment.
ding ding, I found a typo... time to pick up the pieces. heh heh.
| assertRSECodeAndMessage(ex, 400, "Could not find collection", "collection-does-not-exist"); | ||
| } | ||
|
|
||
| private void assertRSECodeAndMessage( |
Contributor
There was a problem hiding this comment.
is there any value in testing here the other ways of making a query like GenericSolrRequest? That it alos throws a 400?
| public void testErrorResponseSurfacesErrorAtTopLevel() throws IOException { | ||
| final var parser = new JacksonDataBindResponseParser<>(SolrJerseyResponse.class); | ||
| final var json = | ||
| "{" |
Contributor
There was a problem hiding this comment.
I've been enjoying use the triple "double quotes" to not have all this string escaping and make reading multiline JSON easier.
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.
https://issues.apache.org/jira/browse/SOLR-17549
Description
Prior to this commit our generated v2 SolrRequest implementations only
reported errors in the POJO itself. A failure response from Solr
wouldn't trigger a RemoteSolrException as SolrJ users are used to with
our v1 APIs.
This was tough for users to remember to do, and even when done properly
ends up looking verbose and ugly.
Solution
This commit updates our v2 SolrJ code to throw RemoteSolrException when
error-responses are encountered.
It relies on a pre-existing attempt at error detection already present in our
SolrClient implementations. Code in many of our clients already attempts to
detect these errors by looking for a 'NamedList' key, "error", which it
(incorrectly) assumed would be present in the v2 case but which isn't
populated by the ResponseParser that our v2 SolrRequest/SolrResponse
implementations use by default.
This commit updates JacksonDatabindResponseParser to populate this
"error" key that SolrClient's were looking for, which in turn enables the
clients to correctly throw RemoteSolrException in these cases.
Tests
Unit tests for JacksonDatabindResponseParser in JacksonDatabindResponseParserTest. An integration test validating the end-to-end behavior has also been added to V2ApiIntegrationTest.
Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.