refactor: 规范Expection处理

This commit is contained in:
xboard
2023-12-04 20:40:49 +08:00
parent aa0fe64afe
commit 0ab7dee52d
65 changed files with 625 additions and 362 deletions
+6 -1
View File
@@ -1,6 +1,7 @@
<?php
namespace App\Http\Routes\V1;
use App\Exceptions\ApiException;
use Illuminate\Contracts\Routing\Registrar;
class ServerRoute
@@ -12,7 +13,11 @@ class ServerRoute
'middleware' => 'server'
], function ($router) {
$router->any('/{class}/{action}', function($class, $action) {
$ctrl = \App::make("\\App\\Http\\Controllers\\V1\\Server\\" . ucfirst($class) . "Controller");
$controllerClass = "\\App\\Http\\Controllers\\V1\\Server\\" . ucfirst($class) . "Controller";
if(!(class_exists($controllerClass) && method_exists($controllerClass, $action))){
throw new ApiException(404,'Not Found');
};
$ctrl = \App::make($controllerClass);
return \App::call([$ctrl, $action]);
});
});