Тёмный

Laravel Service Error: Abort or Throw Exceptions? 

Laravel Daily
Подписаться 145 тыс.
Просмотров 11 тыс.
50% 1

Хобби

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 30   
@newtonjob7611
@newtonjob7611 Год назад
Another good way will be to use the Exception Handler, so that your controller is free of try-catch blocks. Great video as always 👍
@fifthavenue2105
@fifthavenue2105 Год назад
Exceptions are ignored a lot by devs even tho they can be very helpful with tracking the issues, and you can even send an email to devs when a specific exception occurs. Thanks for the video!!
@yungifez
@yungifez Год назад
Exactly I wouldn't say I'd love to individually catch all exceptions I prefer it inherits a base exception class that handles all exceptions like that using the render method
@mikescola
@mikescola Год назад
This is the way. I log mine to slack channels!
@umidkurbanov5495
@umidkurbanov5495 Год назад
You're my real teacher and my hero dear. I really love your videos and the way you teach. Wish you luck forever
@wadecodez
@wadecodez Год назад
I use exceptions then catch them using Laravel’s Error Handing features. It reduced the amount of try/catch blocks. For example if an exception extends an MyApiException then I can choose to always return json, but if it extends MyImageConversionException I may throw an error back to the UI. Another use case is to let exceptions bubble up while in development but only log while in production and provide a generic error like “whoops something went wrong” to the user. If you abort you loose the option to control how errors are handled, and you may have to go back and add exceptions anyways.
@wrbkor23
@wrbkor23 Год назад
same with me
@swancompany_inc
@swancompany_inc Год назад
I think that is a great idea to shoot videos about comments from Laravel Daily. 👍
@sinema7101
@sinema7101 Год назад
Laravel has a neat feature with render functions in custom exceptions. So you are able to throw speaking erros for your API e.g. JSON API conform errors, which are pretty nice. In cli you would still have your call stack and the exception message. Try to avoid try catch blocks in your controllers. Btw a dedicated exceptions with disabled debug (which always should be in production) might be bad for FE devs. They wont see the exception message. Please try to work with granulated exceptions. Generalised catching exceptions/throwables might end in unexpected behaviour. You also can watch fur custom eXceptions in your tests.
@kingstalker
@kingstalker Год назад
Nice video ty short and simple
@LaercioLopesLL
@LaercioLopesLL Год назад
Thank you!
@cardboarddignity
@cardboarddignity Год назад
While watching your video, just realized that Laravel Validation won't throw any exception. And that made me thinking: why not make a course/series of how Laravel works internally? I mean... inspecting Laravel's source code
@LaravelDaily
@LaravelDaily Год назад
There are courses like this, like Laravel Core Adventures by Christoph Rumpel. I don't think it would interest many devs in practice. Also, Laravel would actually throw exception, just handle it automatically.
@mauriciomueller86
@mauriciomueller86 Год назад
I always structure that way. I throw exceptions and the controller is responsible for sending the appropriate message.
@olusolaojewunmi1995
@olusolaojewunmi1995 Год назад
Same here. So I can also return different messages depending on the exception that occurred if I want to.
@villainhd17
@villainhd17 Год назад
It's better to throw a dedicated exception, then use the Exception Handler or renderable exceptions.
@kekesidori
@kekesidori Год назад
Thanks for the video! How can I catch Exception thrown in StoreUserRequest class failedValidation method?
@ercog7921
@ercog7921 Год назад
In order not to turn the entire project into hell with try catch, I use the render method in the exceptions themselves
@sirajul-anik
@sirajul-anik Год назад
Doesn't abort and throw exceptions do the same thing?
@LaravelDaily
@LaravelDaily Год назад
Not exactly
@PoundXI-yu4wf
@PoundXI-yu4wf 6 месяцев назад
implementation of abort() in laravel/framework/src/Illuminate/Foundation/helpers.php It throws one of the following exception classes based on conditions: HttpResponseException, HttpResponseException, NotFoundHttpException, HttpException@@LaravelDaily
@floris3766
@floris3766 11 месяцев назад
If you do multiple service actions inside the controller. Should there be one try catch or separate try catches for each sevice action call individualy? So trying multiple stuff and then catch or all separate try catches.
@LaravelDaily
@LaravelDaily 11 месяцев назад
It's your personal preference how to structure it.
@bulent2435
@bulent2435 Год назад
Thanks.
@glowiever
@glowiever Год назад
I usually throw exceptions. laravel api route automatically return appropriate json with correct response code
@erwinyonathan6348
@erwinyonathan6348 Год назад
is it with or without request header Accept 'application/json' ?
@glowiever
@glowiever Год назад
@@erwinyonathan6348 only with the 'accept: application/json' iirc.
@محمدابراهيم-ظ2ض
422 vs 400
Далее
Complex Seeder: Eloquent Optimization Example
8:20
Просмотров 4,5 тыс.
БАГ ЕЩЕ РАБОТАЕТ?
00:26
Просмотров 270 тыс.
Сколько стоит ПП?
00:57
Просмотров 355 тыс.
API Platform for Laravel: My First Impression
12:39
Просмотров 6 тыс.
Laravel + Service Pattern + DTOs = ❤️❤️❤️
17:52
Blade Component: Refactor Repeating CSS Classes
6:04
4 Tips to Improve Leah's Laravel Code
8:43
Просмотров 4,6 тыс.
Laravel Translations: Store in PHP or JSON Files?
7:34
Laravel Mini CRM for Beginners in 1 Hour: Step-by-Step
1:12:57
Современные мужчины…
0:37
Просмотров 3,6 млн