Source:
<code>public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); webView.clearCache(true); webView.getSettings().setJavaScriptEnabled(true); URLInterceptorWebViewClient client = new URLInterceptorWebViewClient(getActivity(), webView) { private boolean didReceiveError = false; @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { didReceiveError = true; hideLoadingProgress(); pageIsLoaded = false; ViewPagerDownloadManager.instance.done(CourseUnitWebViewFragment.this, false); showErrorMessage(R.string.network_error_message, FontAwesomeIcons.fa_exclamation_circle); } @Override @TargetApi(Build.VERSION_CODES.M) public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { if (request.getUrl().toString().equals(view.getUrl())) { didReceiveError = true; switch (errorResponse.getStatusCode()) { <START> case HttpStatus.FORBIDDEN: <END> case HttpStatus.UNAUTHORIZED: case HttpStatus.NOT_FOUND: EdxCookieManager.getSharedInstance(getContext()) .tryToRefreshSessionCookie(); break; } showErrorMessage(R.string.network_error_message, FontAwesomeIcons.fa_exclamation_circle); } } public void onPageFinished(WebView view, String url) { if (didReceiveError) { didReceiveError = false; return; } if (url != null && url.equals("data:text/html," + EMPTY_HTML)) { } else { pageIsLoaded = true; hideErrorMessage(); } ViewPagerDownloadManager.instance.done(CourseUnitWebViewFragment.this, true); hideLoadingProgress(); } }; client.setAllLinksAsExternal(true); if (ViewPagerDownloadManager.USING_UI_PRELOADING) { if (ViewPagerDownloadManager.instance.inInitialPhase(unit)) { ViewPagerDownloadManager.instance.addTask(this); } else { tryToLoadWebView(true); } } }</code><technical_language>logic applied in onReceivedError callback for similar behaviour devices Marshmallow version</technical_language>

Target:
public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); webView.clearCache(true); webView.getSettings().setJavaScriptEnabled(true); URLInterceptorWebViewClient client = new URLInterceptorWebViewClient(getActivity(), webView) { private boolean didReceiveError = false; @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (failingUrl != null && failingUrl.equals(view.getUrl())) { didReceiveError = true; hideLoadingProgress(); pageIsLoaded = false; ViewPagerDownloadManager.instance.done(CourseUnitWebViewFragment.this, false); showErrorMessage(R.string.network_error_message, FontAwesomeIcons.fa_exclamation_circle); } } @Override @TargetApi(Build.VERSION_CODES.M) public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { if (request.getUrl().toString().equals(view.getUrl())) { didReceiveError = true; switch (errorResponse.getStatusCode()) { case HttpStatus.FORBIDDEN: case HttpStatus.UNAUTHORIZED: case HttpStatus.NOT_FOUND: EdxCookieManager.getSharedInstance(getContext()) .tryToRefreshSessionCookie(); break; } showErrorMessage(R.string.network_error_message, FontAwesomeIcons.fa_exclamation_circle); } } public void onPageFinished(WebView view, String url) { if (didReceiveError) { didReceiveError = false; return; } if (url != null && url.equals("data:text/html," + EMPTY_HTML)) { } else { pageIsLoaded = true; hideErrorMessage(); } ViewPagerDownloadManager.instance.done(CourseUnitWebViewFragment.this, true); hideLoadingProgress(); } }; client.setAllLinksAsExternal(true); if (ViewPagerDownloadManager.USING_UI_PRELOADING) { if (ViewPagerDownloadManager.instance.inInitialPhase(unit)) { ViewPagerDownloadManager.instance.addTask(this); } else { tryToLoadWebView(true); } } }