异常
This commit is contained in:
47
extend/Aether/PHP/Hyperf/RpcException/ErrorCode.php
Normal file
47
extend/Aether/PHP/Hyperf/RpcException/ErrorCode.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Aether\RpcException;
|
||||
|
||||
class ErrorCode
|
||||
{
|
||||
// 系统错误
|
||||
public const SYSTEM_ERROR = 500;
|
||||
|
||||
public const PARAM_ERROR = 400;
|
||||
|
||||
public const AUTH_ERROR = 401;
|
||||
|
||||
public const FORBIDDEN_ERROR = 403;
|
||||
|
||||
public const NOT_FOUND = 404;
|
||||
|
||||
// 业务错误
|
||||
public const DATA_NOT_FOUND = 10001;
|
||||
|
||||
public const ARTICLE_NOT_FOUND = 20001;
|
||||
|
||||
public const NOTICE_NOT_FOUND = 30001;
|
||||
|
||||
public const RPC_CALL_ERROR = 50001;
|
||||
|
||||
/**
|
||||
* 获取错误信息.
|
||||
*/
|
||||
public static function getMessage(int $code): string
|
||||
{
|
||||
$messages = [
|
||||
self::SYSTEM_ERROR => '系统错误',
|
||||
self::PARAM_ERROR => '参数错误',
|
||||
self::AUTH_ERROR => '未授权',
|
||||
self::FORBIDDEN_ERROR => '权限不足',
|
||||
self::NOT_FOUND => '资源不存在',
|
||||
self::DATA_NOT_FOUND => '数据不存在',
|
||||
self::ARTICLE_NOT_FOUND => '文章不存在',
|
||||
self::NOTICE_NOT_FOUND => '公告不存在',
|
||||
];
|
||||
|
||||
return $messages[$code] ?? '未知错误';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user