Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try{
- //Success
- }catch(Exception ex){
- //Codigo que necesito ejecutar
- }
- <?php
- namespace AppExceptions;
- use Config;
- use Exception;
- use IlluminateDatabaseEloquentModelNotFoundException;
- use IlluminateFoundationExceptionsHandler as ExceptionHandler;
- use IlluminateSupportFacadesLang;
- class Handler extends ExceptionHandler
- {
- /**
- * A list of the exception types that are not reported.
- *
- * @var array
- */
- protected $dontReport = [
- //
- ];
- /**
- * A list of the inputs that are never flashed for validation exceptions.
- *
- * @var array
- */
- protected $dontFlash = [
- 'password',
- 'password_confirmation',
- ];
- /**
- * Report or log an exception.
- *
- * @param Exception $exception
- * @return void
- */
- public function report(Exception $exception)
- {
- parent::report($exception);
- }
- /**
- * Render an exception into an HTTP response.
- *
- * @param IlluminateHttpRequest $request
- * @param Exception $exception
- * @return IlluminateHttpResponse
- */
- public function render($request, Exception $exception)
- {
- if ($exception instanceof ModelNotFoundException && $request->wantsJSON()) {
- $modelName = $exception->getModel();
- $className = substr($modelName, strrpos($modelName, '\') + 1);
- $modelIds = implode(', ', $exception->getIds());
- return response()->json([
- Config::get('constants.response.CODE') => Config::get('constants.code.HTTP_NOT_FOUND'),
- Config::get('constants.response.MESSAGE') =>
- $className.' '.$modelIds.' '.Lang::get('generalAPI.NOT_FOUND'),
- Config::get('constants.response.DATA') => []
- ], Config::get('constants.code.HTTP_NOT_FOUND'));
- }
- if ($exception instanceof Exception) {
- return 0;
- }
- return parent::render($request, $exception);
- }
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return IlluminateHttpResponse
- */
- public function show($id)
- {
- //
- try {
- $user = User::with('userInfo')->find($id);
- return SuccessResponse($user->with('userInfo')->find($user->id), Lang::get('messages.FOUND'));
- } catch (Exception $ex) {
- return BadResponse(Lang::get('messages.NOT_FOUND')); //Esto es lo que necesito que se ejecute, no lo que tiene internamente 'Exception'
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement