Browse Source

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
Benjamin Trent 2 months ago
parent
commit
a707654336

+ 5 - 0
docs/changelog/132414.yaml

@@ -0,0 +1,5 @@
+pr: 132414
+summary: Adjust date docvalue formatting to return 4xx instead of 5xx
+area: Search
+type: bug
+issues: []

+ 9 - 1
server/src/main/java/org/elasticsearch/search/DocValueFormat.java

@@ -34,6 +34,7 @@ import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.text.NumberFormat;
 import java.text.ParseException;
+import java.time.DateTimeException;
 import java.time.ZoneId;
 import java.util.Arrays;
 import java.util.Base64;
@@ -304,7 +305,14 @@ public interface DocValueFormat extends NamedWriteable {
 
         @Override
         public String format(long value) {
-            return formatter.format(resolution.toInstant(value).atZone(timeZone));
+            try {
+                return formatter.format(resolution.toInstant(value).atZone(timeZone));
+            } catch (DateTimeException dte) {
+                throw new IllegalArgumentException(
+                    "Failed formatting value [" + value + "] as date with pattern [" + formatter.pattern() + "]",
+                    dte
+                );
+            }
         }
 
         @Override