73 lines
2.8 KiB
PHP
73 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Constants;
|
|
|
|
class ErrorCode
|
|
{
|
|
// Authentication & Authorization
|
|
public const VALIDATION_ERROR = 'validation_error';
|
|
public const SERVER_ERROR = 'server_error';
|
|
public const NOT_FOUND = 'not_found';
|
|
public const UNAUTHORIZED = 'unauthorized';
|
|
public const FORBIDDEN = 'forbidden';
|
|
public const TOKEN_INVALID = 'token_invalid';
|
|
public const TOKEN_EXPIRED = 'token_expired';
|
|
public const INVALID_CREDENTIALS = 'invalid_credentials';
|
|
|
|
// Resource Related
|
|
public const RESOURCE_NOT_FOUND = 'resource_not_found';
|
|
public const RESOURCE_IN_USE = 'resource_in_use';
|
|
|
|
// Request Related
|
|
public const INVALID_REQUEST_FORMAT = 'invalid_request_format';
|
|
public const METHOD_NOT_ALLOWED = 'method_not_allowed';
|
|
public const TOO_MANY_REQUESTS = 'too_many_requests';
|
|
|
|
// Client Related
|
|
public const CLIENT_INACTIVE = 'client_inactive';
|
|
public const CLIENT_NOT_FOUND = 'client_not_found';
|
|
public const CLIENT_HAS_ACTIVE_TOKENS = 'client_has_active_tokens';
|
|
|
|
// Provider Related
|
|
public const PROVIDER_ERROR = 'provider_error';
|
|
public const LLM_PROVIDER_NOT_FOUND = 'llm_provider_not_found';
|
|
public const LLM_REQUEST_FAILED = 'llm_request_failed';
|
|
|
|
private static array $messages = [
|
|
// Authentication & Authorization
|
|
self::VALIDATION_ERROR => '請求參數驗證失敗。',
|
|
self::SERVER_ERROR => '服務器內部錯誤。',
|
|
self::NOT_FOUND => '請求的資源不存在。',
|
|
self::UNAUTHORIZED => '未授權,請先登錄。',
|
|
self::FORBIDDEN => '禁止訪問,權限不足。',
|
|
self::TOKEN_INVALID => '令牌無效。',
|
|
self::TOKEN_EXPIRED => '令牌已過期。',
|
|
self::INVALID_CREDENTIALS => '認證憑據無效。',
|
|
|
|
// Resource Related
|
|
self::RESOURCE_NOT_FOUND => '請求的資源不存在。',
|
|
self::RESOURCE_IN_USE => '資源正在使用中,無法執行操作。',
|
|
|
|
// Request Related
|
|
self::INVALID_REQUEST_FORMAT => '請求格式無效。',
|
|
self::METHOD_NOT_ALLOWED => '請求方法不允許。',
|
|
self::TOO_MANY_REQUESTS => '請求過於頻繁,請稍後再試。',
|
|
|
|
// Client Related
|
|
self::CLIENT_INACTIVE => '客戶帳戶未啟用。',
|
|
self::CLIENT_NOT_FOUND => '客戶不存在。',
|
|
self::CLIENT_HAS_ACTIVE_TOKENS => '客戶有活躍的認證令牌。',
|
|
|
|
// Provider Related
|
|
self::PROVIDER_ERROR => '提供商服務錯誤。',
|
|
self::LLM_PROVIDER_NOT_FOUND => 'LLM 提供商不存在。',
|
|
self::LLM_REQUEST_FAILED => 'LLM 請求失敗。',
|
|
];
|
|
|
|
public static function getMessage(string $code): string
|
|
{
|
|
return self::$messages[$code] ?? '未知錯誤。';
|
|
}
|
|
}
|