Parcourir la source

Fix conversion of BulkWriteExceptions wrapping another exception

Andreas Braun il y a 6 ans
Parent
commit
b7c11b79b9
1 fichiers modifiés avec 6 ajouts et 0 suppressions
  1. 6 0
      lib/Alcaeus/MongoDbAdapter/ExceptionConverter.php

+ 6 - 0
lib/Alcaeus/MongoDbAdapter/ExceptionConverter.php

@@ -32,6 +32,12 @@ class ExceptionConverter
      */
      */
     public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
     public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
     {
     {
+        // Starting with ext-mongodb 1.6.0, errors during bulk write are always wrapped in a BulkWriteException.
+        // If a BulkWriteException wraps another driver exception, use that instead.
+        if ($e instanceof Exception\BulkWriteException && $e->getPrevious() instanceof Exception\Exception) {
+            $e = $e->getPrevious();
+        }
+
         $message = $e->getMessage();
         $message = $e->getMessage();
         $code = $e->getCode();
         $code = $e->getCode();