diff --git a/mongodb/src/main/java/org/restheart/mongodb/handlers/collection/GetCollectionHandler.java b/mongodb/src/main/java/org/restheart/mongodb/handlers/collection/GetCollectionHandler.java index 2470ffd0a..3cf31dba5 100644 --- a/mongodb/src/main/java/org/restheart/mongodb/handlers/collection/GetCollectionHandler.java +++ b/mongodb/src/main/java/org/restheart/mongodb/handlers/collection/GetCollectionHandler.java @@ -22,8 +22,6 @@ import java.util.Optional; -import com.mongodb.MongoException; -import io.undertow.server.HttpServerExchange; import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.json.JsonParseException; @@ -37,6 +35,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.undertow.server.HttpServerExchange; + /** * * @author Andrea Di Cesare {@literal } @@ -114,30 +114,19 @@ public void handleRequest(HttpServerExchange exchange) throws Exception { return; } - try { - data = dbs.getCollectionData( - Optional.ofNullable(request.getClientSession()), - request.rsOps(), - request.getDBName(), - request.getCollectionName(), - request.getPage(), - request.getPagesize(), - sort, - filter, - request.getHintDocument(), - request.getProjectionDocument(), - request.isCache()); - } catch (MongoException me) { - if (me.getMessage().matches(".*Can't canonicalize query.*")) { - // error with the filter expression during query execution - LOGGER.debug("invalid filter expression {}", request.getFilter(), me); - MongoResponse.of(exchange).setInError(HttpStatus.SC_BAD_REQUEST, "wrong request, filter expression is invalid", me); - next(exchange); - return; - } else { - throw me; - } - } + data = dbs.getCollectionData( + Optional.ofNullable(request.getClientSession()), + request.rsOps(), + request.getDBName(), + request.getCollectionName(), + request.getPage(), + request.getPagesize(), + sort, + filter, + request.getHintDocument(), + request.getProjectionDocument(), + request.isCache()); + } if (exchange.isComplete()) { 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 c542d8f47..5c6eb14ba 100644 --- a/mongodb/src/main/java/org/restheart/mongodb/utils/ResponseHelper.java +++ b/mongodb/src/main/java/org/restheart/mongodb/utils/ResponseHelper.java @@ -163,6 +163,13 @@ public static int getHttpStatusFromErrorCode(int code) { case 15998 -> HttpStatus.SC_BAD_REQUEST; // 31249 Path collision case 31249 -> HttpStatus.SC_BAD_REQUEST; + // 168 InvalidPipelineOperator + case 168 -> HttpStatus.SC_BAD_REQUEST; + // 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 default -> HttpStatus.SC_INTERNAL_SERVER_ERROR; }; } @@ -179,14 +186,14 @@ public static String getMessageFromMongoException(MongoException me) { // Query failed with error code 51091 and error message 'Regular expression is invalid: unmatched parentheses' // Query failed with error code 51108 with name 'Location51108' and error message 'invalid flag in regex options: z' on server 127.0.0.1:27017' // Command failed with error 31249 (Location31249): 'Path collision at page.children.children.displayname remaining portion children.children.displayname' on server... - case 2, 51091, 51108, 31249 -> { + case 2, 51091, 51108, 31249, 168, 17276, 31254 -> { var msg = me.getMessage(); var b = msg.indexOf(": '"); var e = msg.indexOf("' on server"); if (b >= 0 && e >= 0) { - yield "Invalid filter: " + msg.substring(b+3, e).strip(); + yield "Invalid query parameter: " + msg.substring(b+3, e).strip(); } else { yield msg; }