multi-store/app/MyBusinessException.php
2024-05-30 21:37:55 +08:00

20 lines
533 B
PHP

<?php
namespace app;
use support\exception\BusinessException;
use Webman\Http\Request;
use Webman\Http\Response;
class MyBusinessException extends BusinessException
{
public function render(Request $request): ?Response
{
// json请求返回json数据
if ($request->expectsJson()) {
return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage(),'show'=>1]);
}
// 非json请求则返回一个页面
return new Response(200, [], $this->getMessage());
}
}