PHP code example of tinywan / think-exception

1. Go to this page and download the library: Download tinywan/think-exception library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tinywan / think-exception example snippets

regexp
composer 
regexp
php think tinywan:exception

return [
    'think\exception\Handle' => tinywan\Handler::class,
];

return [
    // 添加一个订阅类
    'subscribe' => [
        \tinywan\subscribe\ExceptionSubscribe::class,
    ],
];

use tinywan\exception\BadRequestHttpException;

class Token {
    public function issueToken(Request $request): Response
    {
        $params = $request->post();
        if (empty($params)) {
            throw new BadRequestHttpException('账号或密码不能为空');
        }
    }
}

'body' => [
	'error_code' => 200,
	'message' => '请求太多请稍后重试'
]


namespace app\common;

use Throwable;
use tinywan\Handler;

class ErrorHandler extends Handler
{
    /**
     * @desc: 重写处理扩展的异常,增加自己的异常
     * @param Throwable $e
     * @author Tinywan(ShaoBo Wan)
     */
    protected function solveExtraException(Throwable $e): void
    {
        // 用户中心异常处理
        if ($e instanceof \ErrorException) {
            $this->errorMessage = '用户中心异常:'.$e->getMessage();
            $this->errorCode = 400;
            return;
        }
        parent::solveExtraException($e);
    }
}


$message = ' - 自定义错误1: 浏览器版本xxx'. " \n";
$message .= ' - 自定义错误2: 浏览器版本xxx'. " \n";
\tinywan\event\NotifyEvent::dingTalkRobot([], [], '正式', $message);
regexp
vendor/bin/phpstan analyse src
regexp
vendor/bin/php-cs-fixer fix src