Skip to content

Commit a707654

Browse files
authored
Adjust date docvalue formatting to return 4xx instead of 5xx (#132414)
* Adjust date docvalue formatting to return 4xx instead of 5xx * Update docs/changelog/132414.yaml
1 parent 68eff34 commit a707654

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

docs/changelog/132414.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 132414
2+
summary: Adjust date docvalue formatting to return 4xx instead of 5xx
3+
area: Search
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/search/DocValueFormat.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.text.DecimalFormatSymbols;
3535
import java.text.NumberFormat;
3636
import java.text.ParseException;
37+
import java.time.DateTimeException;
3738
import java.time.ZoneId;
3839
import java.util.Arrays;
3940
import java.util.Base64;
@@ -304,7 +305,14 @@ public DateMathParser getDateMathParser() {
304305

305306
@Override
306307
public String format(long value) {
307-
return formatter.format(resolution.toInstant(value).atZone(timeZone));
308+
try {
309+
return formatter.format(resolution.toInstant(value).atZone(timeZone));
310+
} catch (DateTimeException dte) {
311+
throw new IllegalArgumentException(
312+
"Failed formatting value [" + value + "] as date with pattern [" + formatter.pattern() + "]",
313+
dte
314+
);
315+
}
308316
}
309317

310318
@Override

0 commit comments

Comments
 (0)