@@ -358,19 +358,27 @@ - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation
358
358
[channel invokeMethod: @" onState" arguments: @{@" type" : @" startLoad" , @" url" : webView.URL .absoluteString }];
359
359
}
360
360
361
+ - (void )webView : (WKWebView *)webView didFailProvisionalNavigation : (WKNavigation *)navigation withError : (NSError *)error {
362
+ NSString * url = webView.URL == nil ? @" ?" : webView.URL .absoluteString ;
363
+
364
+ [channel invokeMethod: @" onHttpError" arguments: @{@" code" : [NSString stringWithFormat: @" %ld " , error.code], @" url" : url}];
365
+ }
366
+
361
367
- (void )webView : (WKWebView *)webView didFinishNavigation : (WKNavigation *)navigation {
362
368
[channel invokeMethod: @" onState" arguments: @{@" type" : @" finishLoad" , @" url" : webView.URL .absoluteString }];
363
369
}
364
370
365
371
- (void )webView : (WKWebView *)webView didFailNavigation : (WKNavigation *)navigation withError : (NSError *)error {
366
- [channel invokeMethod: @" onError " arguments: @{@" code" : [NSString stringWithFormat: @" %ld " , error.code], @" error" : error.localizedDescription }];
372
+ [channel invokeMethod: @" onHttpError " arguments: @{@" code" : [NSString stringWithFormat: @" %ld " , error.code], @" error" : error.localizedDescription }];
367
373
}
368
374
369
375
- (void )webView : (WKWebView *)webView decidePolicyForNavigationResponse : (WKNavigationResponse *)navigationResponse decisionHandler : (void (^)(WKNavigationResponsePolicy ))decisionHandler {
370
376
if ([navigationResponse.response isKindOfClass: [NSHTTPURLResponse class ]]) {
371
377
NSHTTPURLResponse * response = (NSHTTPURLResponse *)navigationResponse.response ;
372
378
373
- [channel invokeMethod: @" onHttpError" arguments: @{@" code" : [NSString stringWithFormat: @" %ld " , response.statusCode], @" url" : webView.URL .absoluteString }];
379
+ if (response.statusCode >= 400 ) {
380
+ [channel invokeMethod: @" onHttpError" arguments: @{@" code" : [NSString stringWithFormat: @" %ld " , response.statusCode], @" url" : webView.URL .absoluteString }];
381
+ }
374
382
}
375
383
decisionHandler (WKNavigationResponsePolicyAllow );
376
384
}
0 commit comments