Files
hyperf_data/extend/Aether/PHP/Hyperf/RpcException/ErrorCode.php
2025-09-28 14:51:38 +08:00

48 lines
1.1 KiB
PHP

<?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] ?? '未知错误';
}
}