@@ -358,19 +358,27 @@ - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation
358358 [channel invokeMethod: @" onState" arguments: @{@" type" : @" startLoad" , @" url" : webView.URL .absoluteString }];
359359}
360360
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+
361367- (void )webView : (WKWebView *)webView didFinishNavigation : (WKNavigation *)navigation {
362368 [channel invokeMethod: @" onState" arguments: @{@" type" : @" finishLoad" , @" url" : webView.URL .absoluteString }];
363369}
364370
365371- (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 }];
367373}
368374
369375- (void )webView : (WKWebView *)webView decidePolicyForNavigationResponse : (WKNavigationResponse *)navigationResponse decisionHandler : (void (^)(WKNavigationResponsePolicy ))decisionHandler {
370376 if ([navigationResponse.response isKindOfClass: [NSHTTPURLResponse class ]]) {
371377 NSHTTPURLResponse * response = (NSHTTPURLResponse *)navigationResponse.response ;
372378
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+ }
374382 }
375383 decisionHandler (WKNavigationResponsePolicyAllow );
376384}
0 commit comments