From 521c46c0becba95e9fa3a0f858fe9ad9a3388f43 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 5 Feb 2023 11:23:10 -0500 Subject: [PATCH] Don't capture certain error types --- Tusker/Views/Toast/ToastConfiguration.swift | 68 +++++++++++---------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/Tusker/Views/Toast/ToastConfiguration.swift b/Tusker/Views/Toast/ToastConfiguration.swift index 7bc192cc..fbf95daf 100644 --- a/Tusker/Views/Toast/ToastConfiguration.swift +++ b/Tusker/Views/Toast/ToastConfiguration.swift @@ -56,37 +56,7 @@ extension ToastConfiguration { viewController.present(reporter, animated: true) } // TODO: this is a bizarre place to do this, but code path covers basically all errors - switch error.type { - case .invalidRequest, .invalidResponse, .invalidModel(_), .mastodonError(_, _): - let event = Event(error: error) - event.message = SentryMessage(formatted: "\(title): \(error)") - event.tags = [ - "request_method": error.requestMethod.name, - "request_endpoint": error.requestEndpoint.description, - ] - switch error.type { - case .invalidRequest: - event.tags!["error_type"] = "invalid_request" - case .invalidResponse: - event.tags!["error_type"] = "invalid_response" - case .invalidModel(let error): - event.tags!["error_type"] = "invalid_model" - event.extra = [ - "underlying_error": String(describing: error) - ] - case .mastodonError(let code, let error): - event.tags!["error_type"] = "mastodon_error" - event.tags!["response_code"] = "\(code)" - event.extra = [ - "underlying_error": String(describing: error) - ] - default: - break - } - SentrySDK.capture(event: event) - default: - break - } + captureError(error, title: title) } else { self.subtitle = error.localizedDescription self.systemImageName = "exclamationmark.triangle" @@ -116,3 +86,39 @@ fileprivate extension Pachyderm.Client.Error { } } } + +private func captureError(_ error: Client.Error, title: String) { + let event = Event(error: error) + event.message = SentryMessage(formatted: "\(title): \(error)") + event.tags = [ + "request_method": error.requestMethod.name, + "request_endpoint": error.requestEndpoint.description, + ] + switch error.type { + case .invalidRequest: + event.tags!["error_type"] = "invalid_request" + case .invalidResponse: + event.tags!["error_type"] = "invalid_response" + case .invalidModel(let error): + event.tags!["error_type"] = "invalid_model" + event.extra = [ + "underlying_error": String(describing: error) + ] + case .mastodonError(let code, let error): + event.tags!["error_type"] = "mastodon_error" + event.tags!["response_code"] = "\(code)" + event.extra = [ + "underlying_error": String(describing: error) + ] + case .unexpectedStatus(let code): + event.tags!["error_type"] = "unexpected_status" + event.tags!["response_code"] = "\(code)" + default: + return + } + if let code = event.tags!["response_code"], + code == "401" || code == "403" { + return + } + SentrySDK.capture(event: event) +}