-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] #111 디스코드 에러 알림 연동 #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/kuit/findu/data/dataremote/service/WebhookService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.kuit.findu.data.dataremote.service | ||
|
|
||
| import com.kuit.findu.domain.model.DiscordLogBody | ||
| import retrofit2.http.Body | ||
| import retrofit2.http.POST | ||
| import retrofit2.http.Url | ||
|
|
||
| interface WebhookService { | ||
| @POST | ||
| suspend fun sendLog( | ||
| @Url webhookUrl: String, | ||
| @Body body: DiscordLogBody | ||
| ) | ||
| } |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/kuit/findu/data/dataremote/util/DiscordLogger.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.kuit.findu.data.dataremote.util | ||
|
|
||
| import com.kuit.findu.data.dataremote.service.WebhookService | ||
| import com.kuit.findu.domain.model.DiscordLogBody | ||
| import com.kuit.findu.domain.repository.UserInfoRepository | ||
| import javax.inject.Inject | ||
|
|
||
| class DiscordLogger @Inject constructor( | ||
| private val webhookService: WebhookService, | ||
| private val userInfoRepository: UserInfoRepository, | ||
| private val webhookUrl: String, | ||
| ) { | ||
|
|
||
| suspend fun logServerError( | ||
| code: Int, | ||
| method: String, | ||
| url: String, | ||
| ) { | ||
| val deviceId = userInfoRepository.getDeviceId() | ||
| val nickname = userInfoRepository.getNickname() | ||
|
|
||
| val body = DiscordLogBody( | ||
| content = """ | ||
| 🚨 **Server Error 발생** | ||
|
|
||
| 👤 User | ||
| - Nickname: $nickname | ||
| - DeviceId: $deviceId | ||
|
|
||
| 🌐 Request | ||
| - Method: $method | ||
| - Url: $url | ||
| - Code: $code | ||
| """.trimIndent() | ||
| ) | ||
|
|
||
| runCatching { | ||
| webhookService.sendLog(webhookUrl, body) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.kuit.findu.di | ||
|
|
||
| import com.kuit.findu.BuildConfig | ||
| import com.kuit.findu.data.dataremote.service.WebhookService | ||
| import com.kuit.findu.data.dataremote.util.DiscordLogger | ||
| import com.kuit.findu.domain.repository.UserInfoRepository | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object LogModule { | ||
| @Provides | ||
| @Singleton | ||
| fun provideDiscordLogger( | ||
| webhookService: WebhookService, | ||
| userInfoRepository: UserInfoRepository, | ||
| ): DiscordLogger = | ||
| DiscordLogger( | ||
| webhookService, | ||
| userInfoRepository, | ||
| BuildConfig.DISCORD_WEBHOOK_URL, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.kuit.findu.di | ||
|
|
||
| import com.kuit.findu.data.dataremote.service.WebhookService | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import jakarta.inject.Named | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import okhttp3.OkHttpClient | ||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.gson.GsonConverterFactory | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object LogNetworkModule { | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @Named("webhook") | ||
| fun provideWebhookOkHttpClient(): OkHttpClient = | ||
| OkHttpClient.Builder().build() | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @Named("webhook") | ||
| fun provideWebhookRetrofit( | ||
| @Named("webhook") okHttpClient: OkHttpClient | ||
| ): Retrofit = | ||
| Retrofit.Builder() | ||
| .baseUrl("https://discord.com/") | ||
| .client(okHttpClient) | ||
| .addConverterFactory(GsonConverterFactory.create()) | ||
| .build() | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| fun provideWebhookService( | ||
| @Named("webhook") retrofit: Retrofit | ||
| ): WebhookService = | ||
| retrofit.create(WebhookService::class.java) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/kuit/findu/domain/model/DiscordLogBody.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.kuit.findu.domain.model | ||
|
|
||
| data class DiscordLogBody( | ||
| val content: String | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.