Skip to content

Commit

Permalink
🥅 Handle mongodb error 241 (ConversionFailure) to return status code 400
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang committed Mar 26, 2024
1 parent dad521d commit 4bb0805
Showing 1 changed file with 4 additions and 1 deletion.
Expand Up @@ -171,8 +171,10 @@ public static int getHttpStatusFromErrorCode(int code) {
// 17276 Use of undefined variable
case 17276 -> HttpStatus.SC_BAD_REQUEST;
// 1728, Can't canonicalize query: BadValue Projection cannot have a mix of inclusion and exclusion (old error message)
case 17287, 31254 -> HttpStatus.SC_BAD_REQUEST;
// 31254 Cannot do exclusion on field x in inclusion projection
case 17287, 31254 -> HttpStatus.SC_BAD_REQUEST;
// 241 ConversionFailure
case 241 -> HttpStatus.SC_BAD_REQUEST;
default -> HttpStatus.SC_INTERNAL_SERVER_ERROR;
};
}
Expand Down Expand Up @@ -245,6 +247,7 @@ public static String getMessageFromErrorCode(int code) {
case 31138 -> "Invalid $meta sort";
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";
default -> "Error handling the request, see log for more information";
};
}
Expand Down

0 comments on commit 4bb0805

Please sign in to comment.