diff --git a/lib/Models/Model.php b/lib/Models/Model.php index e3d3237377..3776bb11e4 100644 --- a/lib/Models/Model.php +++ b/lib/Models/Model.php @@ -42,7 +42,24 @@ class Model extends \Sudzy\ValidModel { } catch(\Sudzy\ValidationException $e) { $this->setError($e->getValidationErrors()); } catch(\PDOException $e) { - $this->setError($e->getMessage()); + switch($e->getCode()) { + case 23000: + preg_match("/for key \'(.*?)\'/i", $e->getMessage(), $matches); + if(isset($matches[1])) { + $column = $matches[1]; + $this->setError( + sprintf( + __('Another record already exists. Please specify a different "%1$s".'), + $column + ) + ); + } else { + $this->setError($e->getMessage()); + } + break; + default: + $this->setError($e->getMessage()); + } } catch(\Exception $e) { $this->setError($e->getMessage()); }