Преглед на файлове

Fix conversion of BulkWriteExceptions wrapping another exception

Andreas Braun преди 6 години
родител
ревизия
b7c11b79b9
променени са 1 файла, в които са добавени 6 реда и са изтрити 0 реда
  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();