Skip to content

Commit 095a958

Browse files
committed
switch to 400 error instead of 500 when using a non registered writer type
1 parent efbb007 commit 095a958

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

solr/core/src/java/org/apache/solr/response/ResponseWritersRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static QueryResponseWriter getWriter(String writerName, SolrCore core) {
107107
if (writer == null) {
108108
if (!hasWriter(writerName)) {
109109
throw new SolrException(
110-
SolrException.ErrorCode.SERVER_ERROR, "Unknown response writer type: " + writerName);
110+
SolrException.ErrorCode.BAD_REQUEST, "Unknown response writer type: " + writerName);
111111
} else {
112112
writer = getWriter(writerName);
113113
}

solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ public void testIntrospect() throws Exception {
112112
@Test
113113
public void testInvalidWTParamReturnsError() throws Exception {
114114
V2Request request = new V2Request.Builder("/c/" + COLL_NAME + "/get/_introspect").build();
115-
// Using an invalid wt parameter should return a 500 error
115+
// Using an invalid wt parameter should return a 400 error
116116
request.setResponseParser(new InputStreamResponseParser("bleh"));
117117
NamedList<Object> res = cluster.getSolrClient().request(request);
118118
String respString = InputStreamResponseParser.consumeResponseToString(res);
119119

120-
// Should get a 500 Server Error for unknown writer type
120+
// Should get a 400 Server Error for unknown writer type
121121
assertTrue(
122122
"Expected error message about unknown writer type",
123123
respString.contains("Unknown response writer type"));
124-
assertTrue("Expected 500 error code", respString.contains("500"));
124+
assertTrue("Expected 400 error code", respString.contains("400"));
125125
}
126126

127127
@Test
@@ -132,7 +132,7 @@ public void testWTParam() throws Exception {
132132
Map<?, ?> resp = resAsMap(cluster.getSolrClient(), request);
133133
String respString = resp.toString();
134134

135-
assertFalse(respString.contains("<body><h2>HTTP ERROR 500</h2>"));
135+
assertFalse(respString.contains("400"));
136136
assertFalse(
137137
respString.contains(
138138
"<p>Problem accessing /solr/____v2/c/collection1/get/_introspect. Reason:"));

solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ public void testUnsupportedMetricsFormat() throws Exception {
194194

195195
try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
196196
NamedList<Object> res = adminClient.request(req);
197-
// Unknown wt parameter should return a 500 error
198-
assertEquals(500, res.get("responseStatus"));
197+
// Unknown wt parameter should return a 400 error
198+
assertEquals(400, res.get("responseStatus"));
199199
}
200200
}
201201
}

solr/core/src/test/org/apache/solr/response/TestResponseWritersRegistry.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,4 @@ public void testBuiltInWriterFallbackBehavior() {
4646
QueryResponseWriter unknownWriter = ResponseWritersRegistry.getWriter("nonexistent");
4747
assertThat("unknown writer should be null", unknownWriter, is(nullValue()));
4848
}
49-
50-
@Test
51-
public void testBuiltInWriterLimitedSet() {
52-
QueryResponseWriter standardWriter = ResponseWritersRegistry.getWriter("json");
53-
54-
// Built-in writers should NOT include extended format writers (csv, geojson, etc.)
55-
// These should all fall back to json
56-
// I think this json thing is weird... I think it should throw an exception!
57-
assertThat(
58-
"geojson should fall back to json",
59-
ResponseWritersRegistry.getWriter("geojson"),
60-
is(nullValue()));
61-
}
6249
}

0 commit comments

Comments
 (0)