Skip to content

Instantly share code, notes, and snippets.

@ahsanmster
Created December 5, 2017 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahsanmster/c40b758a65266afcd3e08676a73c841f to your computer and use it in GitHub Desktop.
Save ahsanmster/c40b758a65266afcd3e08676a73c841f to your computer and use it in GitHub Desktop.
Doctrine Dbal Exception Handling (User Friendly Error Message)
<?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