diff options
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/RestApiException.java | 4 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiException.java b/container-core/src/main/java/com/yahoo/restapi/RestApiException.java index d9da320499f..68e46a3a9b8 100644 --- a/container-core/src/main/java/com/yahoo/restapi/RestApiException.java +++ b/container-core/src/main/java/com/yahoo/restapi/RestApiException.java @@ -42,6 +42,7 @@ public class RestApiException extends RuntimeException { public static class NotFound extends RestApiException { public NotFound() { this(null, null); } + public NotFound(HttpRequest request) { this("Nothing at '" + request.getUri().getRawPath() + "'", null); } public NotFound(Throwable cause) { this(cause.getMessage(), cause); } public NotFound(String message) { this(message, null); } public NotFound(String message, Throwable cause) { super(ErrorResponse::notFoundError, message, cause); } @@ -50,7 +51,8 @@ public class RestApiException extends RuntimeException { public static class MethodNotAllowed extends RestApiException { public MethodNotAllowed() { super(ErrorResponse::methodNotAllowed, "Method not allowed", null); } public MethodNotAllowed(HttpRequest request) { - super(ErrorResponse::methodNotAllowed, "Method '" + request.getMethod().name() + "' is not allowed", null); + super(ErrorResponse::methodNotAllowed, "Method '" + request.getMethod().name() + "' is not allowed at '" + + request.getUri().getRawPath() + "'", null); } } 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 8ba94f9aca9..d63add5ed1d 100644 --- a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java +++ b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.ListIterator; @@ -144,7 +145,7 @@ class RestApiImpl implements RestApi { private static Route createDefaultRoute() { RouteBuilder routeBuilder = new RouteBuilderImpl("{*}") .defaultHandler(context -> { - throw new RestApiException.NotFound(); + throw new RestApiException.NotFound(context.request()); }); return ((RouteBuilderImpl)routeBuilder).build(); } @@ -155,6 +156,8 @@ class RestApiImpl implements RestApi { if (!disableDefaultMappers){ exceptionMappers.add(new ExceptionMapperHolder<>(RestApiException.class, (context, exception) -> exception.response())); } + // 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)); return exceptionMappers; } |