zoukankan      html  css  js  c++  java
  • tp5开发App 不可预知的异常解决方案

    使用自定义异常 

    'exception_handle'       => 'appcommonexceptionApiHandleException',
    <?php
    /**
     * User: xmz
     * Date: 2020-07-11
     * Time: 01:26
     */
    
    namespace appcommonexception;
    
    
    use appcommonlibShow;
    use Exception;
    use thinkexceptionHandle;
    
    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 appcommonexception;
    
    
    use thinkException;
    
    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;
        }
    }
    

      

  • 相关阅读:
    分享一个详情页
    ES6初探,变量的声明
    ES6初探,什么是ES6
    提问回顾
    个人阅读&个人总结
    结对项目-数独程序扩展
    个人作业Week3-案例分析
    个人作业Week2-代码复审
    个人作业1
    【个人项目】数独
  • 原文地址:https://www.cnblogs.com/aln0825/p/13282197.html
Copyright © 2011-2022 走看看