Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. try{
  2. //Success
  3. }catch(Exception ex){
  4. //Codigo que necesito ejecutar
  5. }
  6.  
  7. <?php
  8.  
  9. namespace AppExceptions;
  10.  
  11. use Config;
  12. use Exception;
  13. use IlluminateDatabaseEloquentModelNotFoundException;
  14. use IlluminateFoundationExceptionsHandler as ExceptionHandler;
  15. use IlluminateSupportFacadesLang;
  16.  
  17. class Handler extends ExceptionHandler
  18. {
  19. /**
  20. * A list of the exception types that are not reported.
  21. *
  22. * @var array
  23. */
  24. protected $dontReport = [
  25. //
  26. ];
  27.  
  28. /**
  29. * A list of the inputs that are never flashed for validation exceptions.
  30. *
  31. * @var array
  32. */
  33. protected $dontFlash = [
  34. 'password',
  35. 'password_confirmation',
  36. ];
  37.  
  38. /**
  39. * Report or log an exception.
  40. *
  41. * @param Exception $exception
  42. * @return void
  43. */
  44. public function report(Exception $exception)
  45. {
  46. parent::report($exception);
  47. }
  48.  
  49. /**
  50. * Render an exception into an HTTP response.
  51. *
  52. * @param IlluminateHttpRequest $request
  53. * @param Exception $exception
  54. * @return IlluminateHttpResponse
  55. */
  56. public function render($request, Exception $exception)
  57. {
  58. if ($exception instanceof ModelNotFoundException && $request->wantsJSON()) {
  59. $modelName = $exception->getModel();
  60. $className = substr($modelName, strrpos($modelName, '\') + 1);
  61. $modelIds = implode(', ', $exception->getIds());
  62.  
  63. return response()->json([
  64. Config::get('constants.response.CODE') => Config::get('constants.code.HTTP_NOT_FOUND'),
  65. Config::get('constants.response.MESSAGE') =>
  66. $className.' '.$modelIds.' '.Lang::get('generalAPI.NOT_FOUND'),
  67. Config::get('constants.response.DATA') => []
  68. ], Config::get('constants.code.HTTP_NOT_FOUND'));
  69. }
  70.  
  71. if ($exception instanceof Exception) {
  72. return 0;
  73. }
  74.  
  75. return parent::render($request, $exception);
  76. }
  77. }
  78.  
  79. /**
  80. * Display the specified resource.
  81. *
  82. * @param int $id
  83. * @return IlluminateHttpResponse
  84. */
  85. public function show($id)
  86. {
  87. //
  88. try {
  89. $user = User::with('userInfo')->find($id);
  90. return SuccessResponse($user->with('userInfo')->find($user->id), Lang::get('messages.FOUND'));
  91. } catch (Exception $ex) {
  92. return BadResponse(Lang::get('messages.NOT_FOUND')); //Esto es lo que necesito que se ejecute, no lo que tiene internamente 'Exception'
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement