yiisoft / yii2-mongodb

Yii 2 MongoDB extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
326 stars 191 forks source link

All error codes in mongodb #306

Open ziaratban opened 4 years ago

ziaratban commented 4 years ago

generated from https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml

Q A
Is bugfix? no
New feature? yes
Breaks BC? no
Tests pass? no

examples

use yii\mongodb\ErrorCode;

try{
    // mongodb commands ...  
}catch(\Exception $e){
    if(ErrorCode::is($e))
        echo 'this is a mongodb error.';
}

try{
    // mongodb commands ...  
}catch(\Exception $e){
    if(ErrorCode::is($e,ErrorCode::WriteConflict))
        echo 'this is a mongodb write conflict error.';
}