Commit c32f0b57e006245b1f637be51297104d973145ee

Authored by 谭苏航
1 parent 22498f16

fix: handle db exceptions in auth

Showing 1 changed file with 15 additions and 3 deletions
@@ -53,16 +53,28 @@ class AuthService @@ -53,16 +53,28 @@ class AuthService
53 } 53 }
54 54
55 // 3. 查找或创建用户 55 // 3. 查找或创建用户
56 - $user = $this->findOrCreateUser($phone, $openid, $unionid); 56 + try {
  57 + $user = $this->findOrCreateUser($phone, $openid, $unionid);
  58 + } catch (Exception $e) {
  59 + $this->logDebug("Exception in findOrCreateUser: " . $e->getMessage());
  60 + return ['ok' => false, 'error' => 'Database Error: ' . $e->getMessage()];
  61 + }
  62 +
57 if (!$user) { 63 if (!$user) {
58 - $this->logDebug("Error: Failed to find/create user"); 64 + $this->logDebug("Error: Failed to find/create user (Result is null)");
59 return ['ok' => false, 'error' => '用户创建失败']; 65 return ['ok' => false, 'error' => '用户创建失败'];
60 } 66 }
61 67
62 $this->logDebug("User ID: " . $user['id']); 68 $this->logDebug("User ID: " . $user['id']);
63 69
64 // 4. 创建 Session 70 // 4. 创建 Session
65 - $token = $this->createSession($user['id']); 71 + try {
  72 + $token = $this->createSession($user['id']);
  73 + } catch (Exception $e) {
  74 + $this->logDebug("Exception in createSession: " . $e->getMessage());
  75 + return ['ok' => false, 'error' => 'Session Error: ' . $e->getMessage()];
  76 + }
  77 +
66 if (!$token) { 78 if (!$token) {
67 $this->logDebug("Error: Failed to create session"); 79 $this->logDebug("Error: Failed to create session");
68 return ['ok' => false, 'error' => 'Session 创建失败']; 80 return ['ok' => false, 'error' => 'Session 创建失败'];
Please register or login to post a comment