-
Notifications
You must be signed in to change notification settings - Fork 414
Ignore cancelled OpenAI dashboard navigation errors (-999) #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,26 @@ final class NavigationDelegate: NSObject, WKNavigationDelegate { | |
| } | ||
|
|
||
| func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { | ||
| if Self.shouldIgnoreNavigationError(error) { | ||
| self.completeOnce(.success(())) | ||
| return | ||
| } | ||
|
Comment on lines
22
to
25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Returning early on Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 375de22. Ignored |
||
| self.completeOnce(.failure(error)) | ||
| } | ||
|
|
||
| func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { | ||
| if Self.shouldIgnoreNavigationError(error) { | ||
| self.completeOnce(.success(())) | ||
| return | ||
| } | ||
| self.completeOnce(.failure(error)) | ||
| } | ||
|
|
||
| nonisolated static func shouldIgnoreNavigationError(_ error: Error) -> Bool { | ||
| let nsError = error as NSError | ||
| return nsError.domain == NSURLErrorDomain && nsError.code == NSURLErrorCancelled | ||
| } | ||
|
|
||
| private func completeOnce(_ result: Result<Void, Error>) { | ||
| guard !self.hasCompleted else { return } | ||
| self.hasCompleted = true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import Foundation | ||
| import Testing | ||
| import WebKit | ||
| @testable import CodexBarCore | ||
|
|
||
| @Suite | ||
| struct OpenAIDashboardNavigationDelegateTests { | ||
| @Test("ignores NSURLErrorCancelled") | ||
| func ignoresCancelledNavigationError() { | ||
| let error = NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled) | ||
| #expect(NavigationDelegate.shouldIgnoreNavigationError(error)) | ||
| } | ||
|
|
||
| @Test("does not ignore non-cancelled URL errors") | ||
| func doesNotIgnoreOtherURLErrors() { | ||
| let error = NSError(domain: NSURLErrorDomain, code: NSURLErrorTimedOut) | ||
| #expect(!NavigationDelegate.shouldIgnoreNavigationError(error)) | ||
| } | ||
|
|
||
| @MainActor | ||
| @Test("cancelled failures complete with success") | ||
| func cancelledFailureCompletesWithSuccess() { | ||
| let webView = WKWebView() | ||
| var result: Result<Void, Error>? | ||
| let delegate = NavigationDelegate { result = $0 } | ||
|
|
||
| delegate.webView(webView, didFail: nil, withError: NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled)) | ||
|
|
||
| switch result { | ||
| case .success?: | ||
| #expect(Bool(true)) | ||
| default: | ||
| #expect(Bool(false)) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
completeOnce(.success(()))forNSURLErrorCancelledin the failure delegates turns an intermediate cancellation into a terminal success. In this class,hasCompletedthen suppresses all later callbacks, so a redirect-driven-999can causeprepareWebViewto resume before the real navigation finishes (or before a later hard failure), which can lead to scraping stale/partial dashboard content and masking real load errors.Useful? React with 👍 / 👎.