Skip to content

Commit

Permalink
[Feature] FireBaseanalytics Error Handler 작성 #594
Browse files Browse the repository at this point in the history
  • Loading branch information
MaraMincho committed Sep 26, 2024
1 parent 387a1db commit 0fac69e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class DiscordErrorHandler {
os_log("Discord Web Hook URL이 잘못되었습니다. 확인해주세요")
return
}
let messages = message.splitByLength(1500)
let messages = message.splitByLength(1800)

Task {
do {
Expand Down
56 changes: 56 additions & 0 deletions Projects/Feature/SSErrorHandler/Sources/FireBaseErrorHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// FireBaseErrorHandler.swift
// SSErrorHandler
//
// Created by MaraMincho on 9/26/24.
// Copyright © 2024 com.oksusu. All rights reserved.
//

import Foundation
import Combine
import Foundation
import OSLog
import SSNotification
import FirebaseAnalytics

// MARK: - DiscordErrorHandler

public final class FireBaseErrorHandler {
public static let shared = FireBaseErrorHandler()
var subscription: AnyCancellable?
private init() {}

public func registerFirebaseLogSystem() {
subscription = NotificationCenter.default.publisher(for: SSNotificationName.logError)
.sink { @Sendable errorObjectOutput in
let errorObject = errorObjectOutput.object as? String
Self.sendErrorToFirebase(errorMessage: errorObject)
}
}

public func removeDiscordLogSystem() {
subscription = nil
}

@Sendable private static func sendErrorToFirebase(errorMessage message: String?) {
guard let message else {
return
}
Analytics.logEvent("iOS Error", parameters: ["description": message])
}
}

private extension String {
func splitByLength(_ length: Int) -> [String] {
var result: [String] = []
var currentIndex = startIndex

while currentIndex < endIndex {
let nextIndex = index(currentIndex, offsetBy: length, limitedBy: endIndex) ?? endIndex
result.append(String(self[currentIndex ..< nextIndex]))
currentIndex = nextIndex
}

return result
}
}

0 comments on commit 0fac69e

Please sign in to comment.