douxun4860 2016-03-04 19:48
浏览 89

如何捕获错误并打印给用户

I'm trying to print the errors that usually come in the gray screen , but capturing them in a html and displaying the user to use the system. For this I am using the render method and a view on the resources / views / errors / error.php folder and I'm doing the following:

public function render($request, Exception $e)
 {
   return response()->view('errors.error', [], 500);
 }

This effectively is showing me what I have in error.php html file but want to show the user the actual error captured.

As I do ? Help !!!

  • 写回答

1条回答 默认 最新

  • dso407787736 2016-03-04 20:20
    关注

    First of all, you have to think if you really want to show the user the error detail. (Probably not). In fact, the detail you see in the "gray screen" varies according to the value of APP_DEBUG in your .env file.

    Typically you want to hide from users the reason behind the failing, and display a very generic error message. For HTTP exceptions, the exception handler will do it for you: just create a blade file for each http code you want to handle (resources/views/errors/404.blade.php for instance).

    If you want this for debugging purposes, there are better tools. Checking the error log is the most basic one. Or use the dd() function here and there to look at the state of some variable at any point.

    If you really really want to do this, you can modify the app/Exceptions/Handler.phpfile, render method as you suggest

    public function render($request, Exception $e)
    {
       return response()->view('errors.error', [
           'error_message' => $e->getMessage()
       ], $code);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)