<?php
/**
 * Author: luzheng.liu
 * Time: 2020/12/5 17:22
 */

namespace app\index\exception;


use app\common\until\Enum;
use app\common\until\Until;
use Error;
use Exception;
use think\exception\Handle;
use think\exception\HttpException;
use think\Response;

class ExceptionHandel extends Handle {

    /**
     * Render an exception into an HTTP response.
     *
     * @access public
     * @param  \Exception $e
     * @return Response
     */
    public function render(Exception $e)
    {
        // 添加自定义异常处理机制
        if ($e instanceof ApiException) {
            Until::output([], $e->getMessage(),Enum::THROW_ERR_CODE);
        }

        if ($e instanceof TokenException) {
            Until::output([], $e->getMessage(),Enum::REFRSEH_TOKEN);
        }

        if ($e instanceof Exception || $e instanceof Error) {
            Until::output([], $e->getMessage().' file:' . str_replace('/mnt/www','ROOT',$e->getFile()) . ' line:' . $e->getLine() ,Enum::THROW_ERR_CODE);
        }
        // 其他错误交给系统处理
        return parent::render($e);

    }
}