diff options
author | Bjørn Christian Seime <bjorncs@vespa.ai> | 2024-02-27 08:05:51 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@vespa.ai> | 2024-02-27 08:05:51 +0100 |
commit | b107fe16cf50d5ffde3499667461103275725e83 (patch) | |
tree | 22862cb398b35342e6f07a20f74f5c7b4483d28f /container-core/src/main/java/com/yahoo | |
parent | 7e89f23fb55879d7265ae74bd218a29df642fe5d (diff) |
Handle `InvalidJsonException` by default. Fix mapper ordering
Diffstat (limited to 'container-core/src/main/java/com/yahoo')
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java | 6 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/RestApiMappers.java | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java index 090e06c221f..e5aeb33d45d 100644 --- a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java +++ b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java @@ -211,7 +211,11 @@ class RestApiImpl implements RestApi { exceptionMappers.addAll(RestApiMappers.DEFAULT_EXCEPTION_MAPPERS); } // Topologically sort children before superclasses, so most the specific match is found by iterating through mappers in order. - exceptionMappers.sort((a, b) -> (a.type.isAssignableFrom(b.type) ? 1 : 0) + (b.type.isAssignableFrom(a.type) ? -1 : 0)); + exceptionMappers.sort((l, r) -> { + if (l.type.equals(r.type)) return 0; + if (l.type.isAssignableFrom(r.type)) return 1; + return -1; + }); return exceptionMappers; } diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiMappers.java b/container-core/src/main/java/com/yahoo/restapi/RestApiMappers.java index 62b46d26ba9..6d785ba58bc 100644 --- a/container-core/src/main/java/com/yahoo/restapi/RestApiMappers.java +++ b/container-core/src/main/java/com/yahoo/restapi/RestApiMappers.java @@ -1,6 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.restapi; +import ai.vespa.json.InvalidJsonException; import ai.vespa.json.Json; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -52,6 +53,7 @@ public class RestApiMappers { (context, entity) -> new JacksonJsonResponse<>(200, entity, context.jacksonJsonMapper(), true))); static List<ExceptionMapperHolder<?>> DEFAULT_EXCEPTION_MAPPERS = List.of( + new ExceptionMapperHolder<>(InvalidJsonException.class, (ctx, e) -> ErrorResponse.badRequest(e.getMessage())), new ExceptionMapperHolder<>(RestApiException.class, (context, exception) -> exception.response())); private RestApiMappers() {} |