From 21f2cee02a85bd894a4dc408f145a92407fe1694 Mon Sep 17 00:00:00 2001 From: Andrea Di Cesare Date: Sat, 18 Jan 2025 09:48:54 +0100 Subject: [PATCH] :bug: Fix: Return 400 Bad Request for invalid sort parameter in mongo service (was 500) --- .../main/java/org/restheart/mongodb/utils/ResponseHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mongodb/src/main/java/org/restheart/mongodb/utils/ResponseHelper.java b/mongodb/src/main/java/org/restheart/mongodb/utils/ResponseHelper.java index f05c2b1a6..b8c33a0f9 100644 --- a/mongodb/src/main/java/org/restheart/mongodb/utils/ResponseHelper.java +++ b/mongodb/src/main/java/org/restheart/mongodb/utils/ResponseHelper.java @@ -175,6 +175,8 @@ public static int getHttpStatusFromErrorCode(int code) { case 17287, 31254 -> HttpStatus.SC_BAD_REQUEST; // 241 ConversionFailure case 241 -> HttpStatus.SC_BAD_REQUEST; + // wrong $sort value (must be 1 or -1) + case 15975 -> HttpStatus.SC_BAD_REQUEST; default -> HttpStatus.SC_INTERNAL_SERVER_ERROR; }; } @@ -248,6 +250,7 @@ public static String getMessageFromErrorCode(int code) { case 40323 -> "A pipeline stage specification object must contain exactly one field."; case 15998 -> "FieldPath field names may not be empty strings"; case 241 -> "Failed to parse number in $convert"; + case 15975 -> "Wrong sort parameter, key ordering must be 1 (for ascending) or -1 (for descending)"; default -> "Error handling the request, see log for more information"; }; }