Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect in WebView a 404 Error

I have a WebView which i set the the onError and the onLoadEnd. The problem is that when i have a web page which returns a 404 not found error, i don't get it in the onError handler. I do get the onLoadEnd but there is no way to know that this is a 404 except the title.

enter image description here

Is there a way to detect that? I was expecting that this would be handled by the onError callback.

like image 815
Amir Avatar asked Mar 17 '26 23:03

Amir


1 Answers

With the current version of react-native-webview, code is a property on the event. Make sure your web server is indeed returning an HTTP code 404, and not just a webpage that says 404 in the title.

<WebView
  source={{ uri: 'https://philihp.com/it-is-a-404' }}
  onError={({ code }) => {
    console.log({ code });
  }}
/>
like image 135
Philihp Busby Avatar answered Mar 20 '26 13:03

Philihp Busby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!