1
我正在使用Lumen和Dingo API構建API。我的註冊功能會檢查指定的電子郵件是否已經存在。Lumen with Dingo API Helpers返回錯誤的狀態代碼
如果電子郵件已存在於數據庫中,則使用Dingo API助手返回錯誤響應。
Dingo\Api\Routing\Helpers
isEmailTaken功能:
private function isEmailtaken($email) {
$userExists = User::where('email', $email)->count();
if($userExists) {
$return['error'] = true;
$return['message'] = "It appears you already have an account with us.";
return $return;
} else {
$return['error'] = false;
return $return;
}
}
註冊函數調用函數,並返回一個錯誤:
$validateEmail = $this->isEmailtaken($email);
if ($validateEmail['error'] == true) {
return $this->response->errorBadRequest($validateEmail['message']);
}
它輸出與JSON響應正確的錯誤代碼正確的錯誤消息:
"{"message":"It appears you already have an account with us.","status_code":400}"
然而,在頭產生的響應狀態正常和代碼是200