laravel-gymie icon indicating copy to clipboard operation
laravel-gymie copied to clipboard

Clean up the controllers and treating exceptions

Open TiagoSilvaPereira opened this issue 6 years ago • 2 comments

Would be great clean up the controllers and move the extra logical code to repositories or models.

I realized that when a problem occurs with the DB::transaction, the controllers are not firing the exception, but only returning a error message. It is very difficult to track the errors occurred when saving or updating data.

Ex:

DB::beginTransaction();

try {
            ...
} catch (\Exception $e) {

            DB::rollback();

            // I think here we can throw an exception, with the message below. Then, on the
            // exceptions handler, we check if the system env is dev or production, to show the error
            // or only flash the message. 

            flash()->error('Error while creating the member');

            return redirect(action('MembersController@index'));

}

TiagoSilvaPereira avatar Mar 14 '18 14:03 TiagoSilvaPereira

I think it's too early to tackle down exception even because on Laravel 5.5 and 5.6 you can handler everything using the renderable interface

ludo237 avatar Mar 14 '18 15:03 ludo237

@TiagoSilvaPereira, not just controllers we will need refactoring at lot more places, currently working on the items list for the same.

ajitbohra avatar Mar 19 '18 15:03 ajitbohra