Skip to content

Commit

Permalink
![FIX] Resolve Unexpected Exception
Browse files Browse the repository at this point in the history
  - Resolve unexpected HTTP 404 exception occurred during network request.
    * Separate Retrofit instance into two individual variables, one for Notice Service, and another one for the FCM service.
  • Loading branch information
doyoonkim3312 committed Oct 14, 2024
1 parent cbc3643 commit c89f075
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/Theme.KNUTICE"
android:directBootAware="true"
tools:targetApi="31">
<activity
android:name="com.doyoonkim.knutice.presentation.MainActivity"
Expand All @@ -29,10 +28,8 @@
</intent-filter>
</activity>
<service android:name="com.doyoonkim.knutice.fcm.PushNotificationHandler"
android:exported="false"
android:directBootAware="true">
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/com/doyoonkim/knutice/data/KnuticeRemoteSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.doyoonkim.knutice.model.TokenInfo
import com.doyoonkim.knutice.model.TopThreeNotices
import com.doyoonkim.knutice.model.ValidateTokenResult
import com.example.knutice.BuildConfig
import com.google.gson.Gson
import com.google.gson.JsonObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
Expand All @@ -28,28 +29,27 @@ import javax.inject.Inject

class KnuticeRemoteSource @Inject constructor() {

private object RetrofitInstance {
private val builder = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
private val noticeService = Retrofit.Builder()
.baseUrl(BuildConfig.API_ROOT)
.addConverterFactory(GsonConverterFactory.create())
.build()

val noticeServiceInstance: Retrofit
get() = builder.baseUrl(BuildConfig.API_ROOT).build()

val fcmServiceInstance: Retrofit
get() = builder.baseUrl(BuildConfig.API_ROOT_FCM).build()
}
private val fcmService = Retrofit.Builder()
.baseUrl(BuildConfig.API_ROOT_FCM)
.addConverterFactory(GsonConverterFactory.create())
.build()

suspend fun getTopThreeNotice(): TopThreeNotices {
Log.d("KnuticeRemoteSource", "Start retrofit service")
return RetrofitInstance.noticeServiceInstance.create(KnuticeService::class.java).run {
return noticeService.create(KnuticeService::class.java).run {
this.getTopThreeNotice()
}
}


suspend fun getNoticeListPerPage(category: NoticeCategory, lastNttId: Int): NoticesPerPage {
Log.d("KnuticeRemoteSource", "Start retrofit service")
return RetrofitInstance.noticeServiceInstance.create(KnuticeService::class.java).run {
return noticeService.create(KnuticeService::class.java).run {
if (lastNttId == 0) {
this.getFirstPageOfNotice(category)
} else {
Expand All @@ -68,9 +68,12 @@ class KnuticeRemoteSource @Inject constructor() {

fun validateToken(token: String) {
CoroutineScope(Dispatchers.IO).launch {
RetrofitInstance.fcmServiceInstance.create(KnuticeService::class.java).validateToken(
fcmService.create(KnuticeService::class.java).validateToken(
TokenInfo(deviceToken = token)
)
).run {
if (this.result?.resultCode == 200) Log.d("KnuticeServer", "Token saved.")
else Log.d("KnuticeServer", "Failed to save token")
}
}
}

Expand Down

0 comments on commit c89f075

Please sign in to comment.