fix: NullReferenceException

This commit is contained in:
AnonymousDotNet 2024-10-30 20:50:23 +08:00
parent 17b08e7834
commit e1d4956d91

View file

@ -14,7 +14,12 @@ public partial class MongoRepository
public User? GetUserByPhone(string phone)
{
string phoneSecond = string.Empty;
if (phone.Length >= 4 && phone.Substring(0, 3) != "+86")
// 如果电话号码长度小于 4直接返回 null
if (phone?.Length < 4)
{
return null;
}
if (phone.Substring(0, 3) != "+86")
{
phoneSecond = $"+86{phone}";
}