title: Best way to load a custom error html file in a webview
body: <ol>
  <li><p>A custom html page is loaded in webview when some error has occurred(internet is disconnected, timeout...) and the failingUrl is saved in viewModel.</p></li>
  <li><p>When reload button is pressed, it tries to reload the failingUrl.</p></li>
  </ol>
  
  <p>The problem is every time I load the custom html file, it is called again in onPageStarted and failingUrl is cleared. So failingUrl is going to be null. How can I know if it is the error page or not when onPageStarted is being called?</p>
  
  <pre><code>webView.setWebViewClient(new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
              super.onPageStarted(view, url, favicon);
              //clear failingUrl
              viewModel.setFailingUrl(null);
          }
  
          @Override
          public void onPageFinished(WebView view, String url) {
              super.onPageFinished(view, url);
  
          }
  
          @Override
          public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
              String htmlData ="&lt;html&gt;&lt;body&gt;" + "ErrorNo: " + errorCode + "&lt;/body&gt;&lt;/html&gt;";
              view.loadDataWithBaseURL(failingUrl, htmlData, "text/html", "UTF-8", failingUrl);
              //save failingUrl
              viewModel.setFailingUrl(failingUrl);
          }
      });
  </code></pre>
  
  <p>reloadButton:</p>
  
  <pre><code>reloadButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
             if (!viewModel.getFailingUrl()) {
                webView.loadUrl(viewModel.getFailingUrl());
                return;
             }
             webView.reload();
          }
  });
  </code></pre>
  
  <p>I could clear the failingUrl when reloadButton is clicked, but it not a good idea. Because if I change the url when webView is back to normal, and press the reloadButton, it will reload the failingUrl.</p>