码迷,mamicode.com
首页 > 移动开发 > 详细

tp5开发App 不可预知的异常解决方案

时间:2020-07-11 10:00:56      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:extend   UNC   异常   common   erro   status   hand   tp5   space   

使用自定义异常 

‘exception_handle‘       => ‘app\common\exception\ApiHandleException‘,
<?php
/**
 * User: xmz
 * Date: 2020-07-11
 * Time: 01:26
 */

namespace app\common\exception;


use app\common\lib\Show;
use Exception;
use think\exception\Handle;

class ApiHandleException extends Handle
{
    public $httpStatus = 500;
    public  function render(Exception $e)
    {
        if(config(‘app_debug‘)){
            return parent::render($e);
        }
        if ($e instanceof ApiException) {
            $this->httpStatus = $e->httpStatus;
        }
      //  return parent::render($e); // TODO: Change the autogenerated stub
       return Show::error($e->getMessage(),0,[],$this->httpStatus);
    }
}

  自定义Exception

<?php
/**
 * User: xmz
 * Date: 2020-07-11
 * Time: 01:37
 */

namespace app\common\exception;


use think\Exception;

class ApiException extends  Exception
{
    public $httpStatus =500;
    public $message = "";
    public $status = 0;

    public function __construct($message = "",$httpStatus = 0,$status =0)
    {
        $this->message = $message;
        $this->httpStatus = $httpStatus;
        $this->status = $status;
    }
}

  

tp5开发App 不可预知的异常解决方案

标签:extend   UNC   异常   common   erro   status   hand   tp5   space   

原文地址:https://www.cnblogs.com/aln0825/p/13282197.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!