1 | <?php |
||
23 | class ExceptionConverter |
||
24 | { |
||
25 | /** |
||
26 | * @param Exception\Exception $e |
||
27 | * @param string $fallbackClass |
||
28 | * |
||
29 | * @return \MongoException |
||
30 | */ |
||
31 | 21 | public static function convertException(Exception\Exception $e, $fallbackClass = 'MongoException') |
|
32 | { |
||
33 | 21 | switch (get_class($e)) { |
|
34 | 21 | case Exception\AuthenticationException::class: |
|
35 | 21 | case Exception\ConnectionException::class: |
|
36 | 21 | case Exception\ConnectionTimeoutException::class: |
|
37 | 21 | case Exception\SSLConnectionException::class: |
|
38 | 8 | $class = 'MongoConnectionException'; |
|
39 | 8 | break; |
|
40 | |||
41 | 13 | case Exception\BulkWriteException::class: |
|
42 | 13 | case Exception\WriteException::class: |
|
43 | 2 | $class = 'MongoCursorException'; |
|
44 | 2 | break; |
|
45 | |||
46 | 11 | case Exception\ExecutionTimeoutException::class: |
|
47 | 1 | $class = 'MongoExecutionTimeoutException'; |
|
48 | 1 | break; |
|
49 | |||
50 | 10 | default: |
|
51 | 10 | $class = $fallbackClass; |
|
52 | 21 | } |
|
53 | |||
54 | 21 | if (strpos($e->getMessage(), 'No suitable servers found') !== false) { |
|
55 | 2 | return new \MongoConnectionException($e->getMessage(), $e->getCode(), $e); |
|
56 | } |
||
57 | |||
58 | 19 | return new $class($e->getMessage(), $e->getCode(), $e); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @throws \MongoException |
||
63 | */ |
||
64 | 8 | public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException') |
|
68 | } |
||
69 |