提交 6d3f89d3 编写于 作者: 李光春's avatar 李光春

- 增加异常处理接管

上级 8ea08b80
......@@ -23,7 +23,7 @@
- 阿里云仓库地址:https://github.com/GC0202/ThinkLibrary
- CODING:https://liguangchun-01.coding.net/p/ThinkLibrary/d/ThinkLibrary/git
- CODING:https://aizhineng.coding.net/p/ThinkLibrary/d/ThinkLibrary/git
- https://liguangchundt.coding.net/p/ThinkLibrary/d/ThinkLibrary/git
- 腾讯云:https://liguangchundt.coding.net/p/ThinkLibrary/d/ThinkLibrary/git
- 微信:https://git.weixin.qq.com/liguangchun/ThinkLibrary
- 华为云:https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
......
......@@ -31,6 +31,7 @@
"ext-iconv": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-http": "*",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"topthink/think-view": "^1.0",
......
......@@ -131,11 +131,12 @@ class Mysql
public function inc(int $int = 1)
{
$cache_value = (int)$this->get();
return Db::table($this->table)
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value + $int
]);
return $result ? true : false;
}
/**
......@@ -148,10 +149,11 @@ class Mysql
public function dec(int $int = 1)
{
$cache_value = (int)$this->get();
return Db::table($this->table)
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value - $int
]);
return $result ? true : false;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use HttpException;
use think\exception\Handle;
use think\exception\ValidateException;
use think\Request;
use think\Response;
use Throwable;
class ThinkException extends Handle
{
/**
* 异常处理接管
* @param Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 参数验证错误
if ($e instanceof ValidateException) {
return json($e->getError(), 422);
}
// 请求异常
if ($e instanceof HttpException && $request->isAjax()) {
return response($e->getMessage(), $e->getStatusCode());
}
// 其他错误交给系统处理
return parent::render($request, $e);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册