mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
second version error exeption
This commit is contained in:
1 parent
62f9a9c020
commit
7e948a82ad
2 files changed
+31
-6
No files matched your search
+9
-6
@@ -202,14 +202,21 @@ class Client
|
||||
$result = BSON\toPHP(substr($res, 21, $responseLength - 21));
|
||||
|
||||
if (property_exists($result, "writeErrors")) {
|
||||
// Throws a Utopia\Mongo\Exception with Code Error
|
||||
|
||||
// Throws Utopia\Mongo\Exception
|
||||
throw new Exception(
|
||||
$result->writeErrors[0]->errmsg,
|
||||
$result->writeErrors[0]->code
|
||||
);
|
||||
}
|
||||
|
||||
if (property_exists($result, 'errmsg')) {
|
||||
// Throws Utopia\Mongo\Exception
|
||||
throw new Exception(
|
||||
'E'.$result->code.' '.$result->codeName.':'.$result->errmsg,
|
||||
$result->code
|
||||
);
|
||||
}
|
||||
|
||||
if (property_exists($result, "n") && $result->ok === 1.0) {
|
||||
return $result->n;
|
||||
}
|
||||
@@ -218,10 +225,6 @@ class Client
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (property_exists($result, 'errmsg')) {
|
||||
throw new Exception($result->errmsg);
|
||||
}
|
||||
|
||||
if ($result->ok === 1.0) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -106,9 +106,31 @@ class MongoTest extends TestCase
|
||||
self::assertIsArray($doc->array);
|
||||
self::assertIsString($doc->date_string);
|
||||
self::assertIsObject($doc->date_object); // Todo: This is not working can't retrieve the object back
|
||||
}
|
||||
|
||||
public function testDriverException()
|
||||
{
|
||||
self::expectException('MongoDB\Driver\Exception\InvalidArgumentException');
|
||||
self::expectExceptionCode(0);
|
||||
new ObjectId('triggerAnError');
|
||||
}
|
||||
|
||||
public function testDuplicationException()
|
||||
{
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionCode(11000);
|
||||
$this->getDatabase()->insert('movies', ['_id' => 999, 'b' => 'Duplication']);
|
||||
}
|
||||
|
||||
public function testExceedTimeException()
|
||||
{
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionCode(50);
|
||||
|
||||
$this->getDatabase()->find(
|
||||
'movies',
|
||||
['$where' => "sleep(1000) || true"],
|
||||
['maxTimeMS'=> 1]
|
||||
)->cursor->firstBatch ?? [];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user