-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥅 Handle MongoDB error 31249 (path collision in projections) to retur…
…n status code 400
- Loading branch information
Showing
1 changed file
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,17 @@ | |
*/ | ||
package org.restheart.mongodb.utils; | ||
|
||
import io.undertow.server.HttpServerExchange; | ||
import io.undertow.util.Headers; | ||
|
||
import com.mongodb.MongoException; | ||
|
||
import org.bson.BsonDocument; | ||
import org.bson.BsonValue; | ||
import org.bson.Document; | ||
import org.bson.types.ObjectId; | ||
import org.restheart.utils.HttpStatus; | ||
|
||
import com.mongodb.MongoException; | ||
|
||
import io.undertow.server.HttpServerExchange; | ||
import io.undertow.util.Headers; | ||
|
||
/** | ||
* | ||
* @author Andrea Di Cesare {@literal <[email protected]>} | ||
|
@@ -161,6 +161,8 @@ public static int getHttpStatusFromErrorCode(int code) { | |
// 31138 Illegal $meta sort | ||
case 15974, 17312, 31138 -> HttpStatus.SC_BAD_REQUEST; | ||
case 15998 -> HttpStatus.SC_BAD_REQUEST; | ||
// 31249 Path collision | ||
case 31249 -> HttpStatus.SC_BAD_REQUEST; | ||
default -> HttpStatus.SC_INTERNAL_SERVER_ERROR; | ||
}; | ||
} | ||
|
@@ -176,7 +178,8 @@ public static String getMessageFromMongoException(MongoException me) { | |
return switch(code) { | ||
// 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' | ||
case 2, 51091, 51108 -> { | ||
// 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 -> { | ||
var msg = me.getMessage(); | ||
|
||
var b = msg.indexOf(": '"); | ||
|