Skip to content

Commit

Permalink
Merge pull request #91 from UbiqueInnovation/feature/nonfatal-error-r…
Browse files Browse the repository at this point in the history
…eporter

Non-fatal error reporter
  • Loading branch information
ubfelix authored Jun 11, 2024
2 parents 6714c30 + 3b437db commit 0a4ffce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Sources/UBFoundation/Logging/UBNonFatalErrorReporter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// UBNonFatalErrorReporter.swift
//
//
// Created by Matthias Felix on 11.06.2024.
//

import Foundation

public enum UBNonFatalErrorReporter {
public static var handler: ((Error) -> Void)?

static func report(_ error: Error) {
handler?(error)
}
}
4 changes: 3 additions & 1 deletion Sources/UBFoundation/Networking/UBURLDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ public final class UBURLDataTask: UBURLSessionTask, CustomStringConvertible, Cus
(.cancelled, .waitingExecution): // Restart task
break
default:
fatalError("Invalid state transition from \(_state) -> \(newValue)")
let errorMessage = "Invalid state transition from \(_state) -> \(newValue)"
assertionFailure(errorMessage)
UBNonFatalErrorReporter.report(NSError(domain: "UBURLDataTask", code: 0, userInfo: [NSLocalizedDescriptionKey: errorMessage]))
}
}
didSet {
Expand Down

0 comments on commit 0a4ffce

Please sign in to comment.