Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
[iOS SDK] Improved error reporting (#26983)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyhlsb authored May 24, 2023
1 parent b8b61ec commit 1b8af06
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct SentryConfiguration: Codable {
struct SentryConfiguration: Codable, Equatable {
let dsn: String
let env: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ final class InitializeInteractorImpl: InitializeInteractor {

sentryConfigurationObserver = deviceRepository
.watchSentryConfiguration()
.removeDuplicates()
.sink(receiveValue: { [errorReporter, environment] configuration in
errorReporter.enable(dsn: configuration.dsn, env: configuration.env, sdkVersion: environment.version)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class SetCurrentUserInteractorImpl: SetCurrentUserInteractor {
func execute(userId: String) throws {
if let previousUser = userRepository.getCurrentUser() {
if previousUser.id == userId {
logger.error(message: "User already authenticated.")
logger.info(message: "User already authenticated.")
return
} else {
logger.error(message: "Trying to authenticate a new user, you must clear the previous one first by calling `clearCurrentUser()`.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,21 @@ final class SentryErrorReporter: ErrorReporter {
}

func reportWarning(message: String, error: Error?, extra: [String: Any]) {
logger.debug(message: "ErrorReporter report warning: \(message)")
let event = makeEvent(level: .warning, message: message, error: error, extra: extra)
hub?.capture(event: event)
}

func reportError(message: String, error: Error?, extra: [String: Any]) {
logger.debug(message: "ErrorReporter report error: \(message)")
let event = makeEvent(level: .error, message: message, error: error, extra: extra)
hub?.capture(event: event)
}

func reportEvent(message: String, extra: [String: Any]) {
logger.debug(message: "ErrorReporter report event (message: \(message))")
let event = makeEvent(level: .info, message: message, error: nil, extra: extra)
hub?.capture(event: event)
}

func log(message: String, extra: [String: Any]?, domain: String?) {
logger.debug(message: "ErrorReporter log message \(message)")
let breadcrumb = Breadcrumb()
breadcrumb.message = message
breadcrumb.level = .info
Expand Down
8 changes: 4 additions & 4 deletions Sources/NablaCore/Utils/Logger/ErrorReporterLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class ErrorReporterLogger: Logger {
errorReporter.setTag(name: "OSVersion", value: OSVersion)
}

public func debug(message _: @autoclosure () -> String, error _: Error?, extra _: [String: Any]) {
// No-op
public func debug(message: @autoclosure () -> String, error _: Error?, extra: [String: Any]) {
errorReporter.log(message: message(), extra: extra)
}

public func info(message _: @autoclosure () -> String, error _: Error?, extra _: [String: Any]) {
// No-op
public func info(message: @autoclosure () -> String, error _: Error?, extra: [String: Any]) {
errorReporter.log(message: message(), extra: extra)
}

public func warning(message: @autoclosure () -> String, error: Error?, extra: [String: Any]) {
Expand Down

0 comments on commit 1b8af06

Please sign in to comment.