auth to server-V28
This commit is contained in:
parent
49cf0d408a
commit
e96e3d9843
1 changed files with 5 additions and 3 deletions
|
|
@ -4,15 +4,17 @@ import com.example.login_v3.data.api.TecnologiaApi
|
|||
import com.example.login_v3.data.api.api_class.UserProfile
|
||||
import javax.inject.Inject
|
||||
|
||||
class Personal_Profile_Repository @Inject constructor(
|
||||
class PersonalProfileRepository @Inject constructor(
|
||||
private val api: TecnologiaApi
|
||||
) {
|
||||
suspend fun getMyProfile(): UserProfile {
|
||||
val response = api.getUserProfile()
|
||||
if (response.isSuccessful) {
|
||||
return response.body()!!
|
||||
// body()!! 雖然簡單,但建議確保 API 回傳格式正確
|
||||
return response.body() ?: throw Exception("回傳資料為空")
|
||||
} else {
|
||||
throw Exception("API error: ${response.code()}")
|
||||
// 這裡可以根據 response.code() 給出更詳細的錯誤訊息
|
||||
throw Exception("讀取失敗 (${response.code()})")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue