Skip to content

Commit

Permalink
🐛 Fix: Return 400 Bad Request for invalid sort parameter in mongo ser…
Browse files Browse the repository at this point in the history
…vice (was 500)
  • Loading branch information
ujibang committed Jan 18, 2025
1 parent f460830 commit 21f2cee
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down Expand Up @@ -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";
};
}
Expand Down

0 comments on commit 21f2cee

Please sign in to comment.