GithubHelp home page GithubHelp logo

tinywan / webman-exception Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 5.0 108 KB

exception handler library for webman plugin

Home Page: https://www.workerman.net/webman

License: MIT License

PHP 100.00%
webman workerman php php-library tinywan exception-handling exceptions webman-framework handler composer

webman-exception's Issues

composer require 报错

> post-package-install: support\Plugin::install
Script support\Plugin::install handling the post-package-install event terminated with an exception
Downloading https://packagist.org/downloads/
[201] https://packagist.org/downloads/

In ClassLoader.php line 582:
                                                                                                                                         
  [ErrorException]                                                                                                                       
  include(/mnt/projects/app-backend/vendor/tinywan/exception-handler/src/Install.php): failed to open stream: No such file or directory  
                                                                                                                                         

Exception trace:
  at phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php:582
 Composer\Util\ErrorHandler::handle() at phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php:582
 include() at phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php:582
 Composer\Autoload\{closure}() at phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php:433
 Composer\Autoload\ClassLoader->loadClass() at n/a:n/a
 spl_autoload_call() at n/a:n/a
 defined() at /mnt/projects/app-backend/vendor/workerman/webman-framework/src/support/Plugin.php:23
 support\Plugin::install() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:439
 Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:257
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:148
 Composer\EventDispatcher\EventDispatcher->dispatchPackageEvent() at phar:///usr/local/bin/composer/src/Composer/Installer/InstallationManager.php:396
 Composer\Installer\InstallationManager::Composer\Installer\{closure}() at phar:///usr/local/bin/composer/src/Composer/Installer/InstallationManager.php:411
 Composer\Installer\InstallationManager->executeBatch() at phar:///usr/local/bin/composer/src/Composer/Installer/InstallationManager.php:319
 Composer\Installer\InstallationManager->downloadAndExecuteBatch() at phar:///usr/local/bin/composer/src/Composer/Installer/InstallationManager.php:218
 Composer\Installer\InstallationManager->execute() at phar:///usr/local/bin/composer/src/Composer/Installer.php:797
 Composer\Installer->doInstall() at phar:///usr/local/bin/composer/src/Composer/Installer.php:622
 Composer\Installer->doUpdate() at phar:///usr/local/bin/composer/src/Composer/Installer.php:287
 Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/RequireCommand.php:490
 Composer\Command\RequireCommand->doUpdate() at phar:///usr/local/bin/composer/src/Composer/Command/RequireCommand.php:339
 Composer\Command\RequireCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:1040
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:378
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:141
 Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:88
 require() at /usr/local/bin/composer:29

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>...]

走到安装插件的这一步就报错了,虽然再安装一次就不报错了,但是运行起来会有问题,config方法获取不了配置了。

您好我这边安装后 这个报错

Webman\Exception\NotFoundException: Class 'Tinywan\ExceptionHandler\Handler' not found in /www/wwwroot/cg.nodebug.cn/vendor/workerman/webman-framework/src/Container.php:68 Stack trace: #0 /www/wwwroot/cg.nodebug.cn/vendor/workerman/webman-framework/src/App.php(259): Webman\Container->make() #1 /www/wwwroot/cg.nodebug.cn/vendor/workerman/webman-framework/src/App.php(354): Webman\App::exceptionResponse() #2 /www/wwwroot/cg.nodebug.cn/support/middleware/CrossMiddleware.php(13): Webman\App::Webman{closure}() #3 /www/wwwroot/cg.nodebug.cn/vendor/workerman/webman-framework/src/App.php(341): support\middleware\CrossMiddleware->process() #4 /www/wwwroot/cg.nodebug.cn/vendor/workerman/webman-framework/src/App.php(141): Webman\App::Webman{closure}() #5 /www/wwwroot/cg.nodebug.cn/vendor/workerman/workerman/Connection/TcpConnection.php(646): Webman\App->onMessage() #6 /www/wwwroot/cg.nodebug.cn/vendor/workerman/workerman/Events/Select.php(311): Workerman\Connection\TcpConnection->baseRead() #7 /www/wwwroot/cg.nodebug.cn/vendor/workerman/workerman/Worker.php(1629): Workerman\Events\Select->loop() #8 /www/wwwroot/cg.nodebug.cn/vendor/workerman/workerman/Worker.php(1423): Workerman\Worker::forkOneWorkerForLinux() #9 /www/wwwroot/cg.nodebug.cn/vendor/workerman/workerman/Worker.php(1397): Workerman\Worker::forkWorkersForLinux() #10 /www/wwwroot/cg.nodebug.cn/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers() #11 /www/wwwroot/cg.nodebug.cn/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\Worker::runAll() #12 /www/wwwroot/cg.nodebug.cn/start.php(4): support\App::run() #13 {main}

event 问题

app.php 下的 event 与 webman/event 存在冲突

image

按文档无法正确得到预期异常: BadRequestHttpException, MethodNotAllowedException

如题.版本 krisss/docker-webman:8.0-cli-alpine
需要按文档重写handler方法
protected function solveAllException(Throwable $e)
{
if ($e instanceof BaseException) {
$this->statusCode = $e->statusCode;
$this->header = $e->header;
$this->errorCode = $e->errorCode;
$this->errorMessage = $e->errorMessage;
$this->error = $e->error;
if (isset($e->data)) {
$this->responseData = array_merge($this->responseData, $e->data);
}
return ; // 在这里直接返回,否则会被下面的方法接管结果.导致500,Internal Server Error
}
$this->solveExtraException($e);
}

扩展自己的 Handler

使用文档中的方法,拓展自己的Handler,并不能生效。请问还需要其他配置吗?

namespace support;

use hg\apidoc\exception\HttpException;
use Tinywan\ExceptionHandler\Handler;

class ErrorHandler extends Handler
{
/**
* @inheritdoc
*/
protected function solveExtraException(\Throwable $e): void
{
// 当前项目下的异常扩展
if ($e instanceof HttpException) {
$this->errorMessage = 'Apidoc异常';
$this->statusCode = 401;
return;
}
parent::solveExtraException($e);
}
}

自定义body没生效

问题描述
Exception 异常插件,自定义body没生效,不知道是不是使用方式不对
image

根据插件文档配置
image

配置代码
image

接口返回
image

utf8_encode php8.2版本弃用了。抛出钉钉时候报错

首先很感谢作者的付出。插件很好用。
使用的问题请留意。一个是格式函数弃用,另外一个dingtalk key多了下划线代码对应不上。

class DingTalkRobotEvent

private static function _sign(string $url, string $secret): string
{
[$s1, $s2] = explode(' ', microtime());
$timestamp = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
$data = $timestamp . "\n" . $secret;
$signStr = base64_encode(hash_hmac('sha256', $data, $secret, true));
#这部分做的兼容
if(PHP_VERSION_ID < 82000){
$signStr = mb_convert_encoding($signStr, 'UTF-8', 'ISO-8859-1');
} else {
$signStr = utf8_encode(urlencode($signStr));
}
$signStr = mb_convert_encoding(urlencode($signStr), 'UTF-8', 'ISO-8859-1');
return $url . "&timestamp=$timestamp&sign=$signStr";
}

1.3.3升级1.5.0出现异常

这是我的配置文件内容
因为我的逻辑需要用到error_code,所以更改了原来默认的code=>200为'error_code'=>200
// 自定义响应消息 'body' => [ 'error_code' => 200, 'msg' => '服务器内部异常', 'data' => null ],

抛出异常
throw new UnauthorizedHttpException('Fail 1', ['errorCode' => 3001]);

v1.3.3版本正常输出
[ "error_code": 3001, "msg": "success", "data": "data" ]

下面是V1.5.0返回的内容,error_code输出的默认值
[ "error_code": 200, "msg": "success", "data": "data" ]

BaseException 适配一下getMessage()

在BaseException类中

public function __construct(string $errorMessage = '', array $params = [])
    {
        parent::__construct();
        if (!empty($errorMessage)) {
            $this->errorMessage = $errorMessage;
            $this->message=$errorMessage;//加一行这个可好
        }
        if (!empty($params)) {
            if (array_key_exists('statusCode', $params)) {
                $this->statusCode = $params['statusCode'];
            }
            if (array_key_exists('header', $params)) {
                $this->header = $params['header'];
            }
            if (array_key_exists('errorCode', $params)) {
                $this->errorCode = $params['errorCode'];
            }
            if (array_key_exists('data', $params)) {
                $this->data = $params['data'];
            }
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.