Prevent default error website when getting error from a DataBase transaction


I want to know how to prevent the default error website to be shown and instead just get the code in order to return it with an `echo json_encode()`

Thank you

View Replies:
mlocati replied on at Permalink Reply
Everything is explained here:

BTW, here's what you can do:

1) Edit the file application/config/app.php:

return array(
    'providers' => array(
        'core_whoops' => '\Application\Src\Custom\CustomWhoopsServiceProvider',

2) Create a new file at application/src/Custom/CustomWhoopsServiceProvider.php:

namespace Application\Src\Custom;
use Concrete\Core\Error\Handler\ErrorHandler;
use Concrete\Core\Error\Handler\JsonErrorHandler;
use Concrete\Core\Error\Run\PHP7CompatibleRun;
use Concrete\Core\Foundation\Service\Provider;
use Whoops\Handler\PlainTextHandler;
use Whoops\Run;
class CustomWhoopsServiceProvider extends Provider
     * {@inheritdoc}
     * @see Provider::register()

3) Create a new file at application/src/Custom/DatabaseExceptionHandler.php:

namespace Application\Src\Custom;
use Whoops\Handler\Handler;
class DatabaseExceptionHandler extends Handler
    public function handle()
        $e = $this->getException();
        if (!($e instanceof \Doctrine\DBAL\DBALException)) {
            return Handler::DONE;
        echo json_encode(['error' => $e->getMessage()]);
        return Handler::QUIT;
titanve replied on at Permalink Reply
Dear Michele,

Thank you for your help. I will try what you suggest

Have a nice day

On Thu, Aug 18, 2016, 04:55 concrete5 Community <>