diff --git a/Projects/Feature/SSErrorHandler/Sources/DiscordErrorHandler.swift b/Projects/Feature/SSErrorHandler/Sources/DiscordErrorHandler.swift index 3b8cc245..b3955865 100644 --- a/Projects/Feature/SSErrorHandler/Sources/DiscordErrorHandler.swift +++ b/Projects/Feature/SSErrorHandler/Sources/DiscordErrorHandler.swift @@ -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 { diff --git a/Projects/Feature/SSErrorHandler/Sources/FireBaseErrorHandler.swift b/Projects/Feature/SSErrorHandler/Sources/FireBaseErrorHandler.swift new file mode 100644 index 00000000..cd24aac4 --- /dev/null +++ b/Projects/Feature/SSErrorHandler/Sources/FireBaseErrorHandler.swift @@ -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 + } +}