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

Commit

Permalink
Merge pull request #56 from nodes-vapor/feature/improve-reporting
Browse files Browse the repository at this point in the history
Feature/improve reporting
  • Loading branch information
siemensikkema authored May 16, 2019
2 parents 8506831 + 70e7754 commit dcc433c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.1
// swift-tools-version:4.2
import PackageDescription

let package = Package(
Expand Down
34 changes: 29 additions & 5 deletions Sources/Bugsnag/Bugsnag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,23 @@ struct BugsnagEvent: Encodable {
self.app = app
self.breadcrumbs = breadcrumbs
self.exceptions = [BugsnagException(error: error, stacktrace: stacktrace)]
self.metaData = BugsnagMetaData(
meta: [
"Error localized description": error.localizedDescription,
"Request debug description": httpRequest.debugDescription
].merging(metadata.mapValues { $0.debugDescription }) { a, b in b }

let nsError = error as NSError
let errorCode: Int? = nsError.code == 0 ? nil : nsError.code
let userInfo = nsError.userInfo.mapValues { String(describing: $0) }

self.metaData = BugsnagMetaData(meta: [
"Error code": errorCode?.description,
"Error domain": nsError.domain,
"Error localized description": error.localizedDescription,
"Error localized failure reason": nsError.localizedFailureReason,
"Error localized recovery options": nsError.localizedRecoveryOptions?
.joined(separator: ","),
"Error localized recovery suggestion": nsError.localizedRecoverySuggestion
]
.compactMapValues { $0 }
.merging(userInfo) { a, b in b }
.merging(metadata.mapValues { $0.debugDescription }) { a, b in b }
)
self.payloadVersion = payloadVersion
self.request = httpRequest.map { BugsnagRequest(httpRequest: $0, keyFilters: keyFilters) }
Expand All @@ -56,6 +68,18 @@ struct BugsnagEvent: Encodable {
}
}

#if swift(>=5.0)
#else
extension Dictionary {
func compactMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> [Key : T] {
return try .init(uniqueKeysWithValues: compactMap {
guard let value = try transform($0.value) else { return nil }
return ($0.key, value)
})
}
}
#endif

struct BugsnagException: Encodable {
let errorClass: String
let message: String
Expand Down

0 comments on commit dcc433c

Please sign in to comment.