10

If you look at the code here:

https://github.com/evernote/evernote-sdk-ios/blob/master/evernote-sdk-ios/internal/ENOAuthViewController.m

that implement OAuth 2.0 flow in UIWebView.

The author uses this code for the didFailLoadWithError delegate function:

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {

        return;
    }

    if (error.code == NSURLErrorCancelled) {
        // ignore rapid repeated clicking (error code -999)
        return;
    }
}

Why is he ignoring those two errors (NSURLErrorCancelled) and error code 102?

Pang
  • 9,564
  • 146
  • 81
  • 122
Kermit the Frog
  • 3,949
  • 7
  • 31
  • 39

2 Answers2

15

Error code 102 from the WebKitErrorDomain is the error that is raised by the UIWebView if its delegate returns FALSE from webView:shouldStartLoadWithRequest:navigationType. When implementing the OAuth2 flow with a UIWebView it is common to do this when the final redirection URL is encountered as this means it's time to hide the web view and start the process of exchanging the access code in the URL with an token directly from the authentication provider.

The second error is something I'm less familiar with but based on the code comment provided and the accepted answer to this question, I suspect there's some logic in the browser or UIWebView that automatically filters out fast repeated clicks. The error is probably being raised by design so that delegates can be notified of this if they're interested.

Community
  • 1
  • 1
steve84
  • 213
  • 3
  • 8
2

from wiki

102 Processing (WebDAV; RFC 2518) As a WebDAV request may contain many sub-requests involving file operations, it may take a long time to complete the request. This code indicates that the server has received and is processing the request, but no response is available yet.[3] This prevents the client from timing out and assuming the request was lost.

from

WebKitErrorDomain A string used by NSError to indicate that the error was originated by a WebKit class.

looks loke web kit errors are something internal and author do not want to handle this error

UPDATE

do not see that there's && in condition. So that mean that if WebKitErrorDomain appears and code is 102 -- that means that web kit can not show page for now, because there're too many sub-requests and you have to wait a bit

Community
  • 1
  • 1
in.disee
  • 1,102
  • 1
  • 7
  • 15