-
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
Open
t1nm1ksun
wants to merge
4
commits into
develop
Choose a base branch
from
feat/discord-notification
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all 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 okhttp3.OkHttpClient | ||
| import retrofit2.Retrofit | ||
| import retrofit2.converter.gson.GsonConverterFactory | ||
| import javax.inject.Named | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
속성 누락 시 빌드 실패 가능성 확인 필요
local.properties에DISCORD_WEBHOOK_URL이 없을 경우 빌드가 실패할 수 있습니다. 다른 개발자나 CI/CD 환경에서 문제가 발생할 수 있으니, 속성 존재 여부 확인 후 기본값 제공 또는 명확한 에러 메시지 추가를 고려해보세요.🔎 제안하는 안전한 처리 방법
또는 개발 환경에서 빈 문자열을 기본값으로 사용:
📝 Committable suggestion
🤖 Prompt for AI Agents