Created
December 5, 2017 12:52
-
-
Save ahsanmster/c40b758a65266afcd3e08676a73c841f to your computer and use it in GitHub Desktop.
Doctrine Dbal Exception Handling (User Friendly Error Message)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services; | |
use Exception; | |
use Log; | |
/** | |
* @param Exception $exception | |
* @return string | |
*/ | |
protected function generateException($exception) | |
{ | |
$code = $exception->getCode(); | |
$message = ''; | |
switch ($code) { | |
case '23000': | |
$message = 'Duplicate Entry'; | |
break; | |
default: | |
Log::info('unhandled exception code:'.$code); | |
$message = $exception->getMessage(); | |
} | |
return $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment