this question is identical to the following: WKWebView catch HTTP error codes; unfortunately the methods in Obj-C are not applicable to Swift 4, thus the cited WKNavigationResponse.response
is no longer of type NSHTTPURLResponse
so it doesn't have the http status code.
But the issue is still the same: I need to get the http status code of the answer to detect if the expected page is loaded or not.
Please note that webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)
delegate is not called in case of 404
but only in case of network issue (i.e. server offline); the func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
is called instead.
Thanks a lot for your answers.