using System; namespace PCL.Core.Minecraft.IdentityModel; /// /// IdentityModel 模块异常基类。 /// public class IdentityModelException(string message, Exception? innerException = null) : Exception(message, innerException); /// /// IdentityModel 配置或元数据不满足当前认证流程要求时抛出的异常。 /// public class IdentityModelConfigurationException(string message, Exception? innerException = null) : IdentityModelException(message, innerException); /// /// 认证服务器返回 OAuth/Yggdrasil 协议错误时抛出的异常。 /// /// 协议错误代码。 /// 协议错误描述。 /// 内部异常。 public class IdentityModelAuthenticationException( string? error, string? errorDescription, Exception? innerException = null) : IdentityModelException(_BuildMessage(error, errorDescription), innerException) { /// /// 协议错误代码。 /// public string? Error { get; } = error; /// /// 协议错误描述。 /// public string? ErrorDescription { get; } = errorDescription; private static string _BuildMessage(string? error, string? errorDescription) { if (!string.IsNullOrWhiteSpace(error) && !string.IsNullOrWhiteSpace(errorDescription)) return $"认证失败:{error} - {errorDescription}"; if (!string.IsNullOrWhiteSpace(errorDescription)) return $"认证失败:{errorDescription}"; if (!string.IsNullOrWhiteSpace(error)) return $"认证失败:{error}"; return "认证失败"; } }