Browse Source

Fix conversion of BulkWriteExceptions wrapping another exception

Andreas Braun 6 năm trước cách đây
mục cha
commit
b7c11b79b9
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  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')
     {
+        // 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();
         $code = $e->getCode();