Skip to content

Commit

Permalink
refactor: 优化api抛出异常信息提示
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Jun 20, 2023
1 parent 38293ff commit 1ef5d1e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use App\System\Service\SystemAppService;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mine\Exception\NoPermissionException;
use Mine\Exception\NormalStatusException;
use Mine\Exception\TokenException;
use Mine\Helper\MineCode;
use Mine\MineApi;
use Hyperf\HttpServer\Annotation\Controller;
Expand Down Expand Up @@ -93,9 +95,15 @@ public function v1(): ResponseInterface
$error = array_shift($error);
}
throw new NormalStatusException(t('mineadmin.interface_exception') . $error, MineCode::INTERFACE_EXCEPTION);
} else {
throw new NormalStatusException(t('mineadmin.interface_exception') . $e->getMessage(), MineCode::INTERFACE_EXCEPTION);
}
if ($e instanceof NoPermissionException) {
throw new NormalstatusException( t( key: 'mineadmin.api_auth_fail') . $e->getMessage(), code: MineCode::NO_PERMISSION);
}
if ($e instanceof TokenException) {
throw new NormalstatusException( t( key: 'mineadmin.api_auth_exception') . $e->getMessage(), code: MineCode::TOKEN_EXPIRED);
}

throw new NormalstatusException( t( key: 'mineadmin.interface_exception') . $e->getMessage(), code: MineCode::INTERFACE_EXCEPTION);
}
}

Expand Down

0 comments on commit 1ef5d1e

Please sign in to comment.