Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to get the HTTP Status of the last request #242

Open
Tommyten opened this issue Oct 17, 2024 · 1 comment
Open

Add a way to get the HTTP Status of the last request #242

Tommyten opened this issue Oct 17, 2024 · 1 comment

Comments

@Tommyten
Copy link

I have already commented here.

Exposing the HTTP Status code of the last request to compose would be helpful for scenarios, where you want to respond to errors coming from requests made by the webview.

Some examples are: Showing Compose Snackbars or Dialogs when a 404 occurs; Setting an authentication cookie when the webview 401s, etc.

@Tommyten
Copy link
Author

I have looked further at this issue and have built a small PoC.
For this I have added a SnapshotStateList of Integers to the WebViewState and in the AccompanistWebViewClient I have overridden the onReceivedHttpError Method, so that when an HttpError is occured the status code is taken from the WebResourceResponse and published to the new SnapshotStateList in the WebViewState. Similarly on iOS, I have overridden fun webView(webView: WKWebView, decidePolicyForNavigationResponse: WKNavigationResponse, decisionHandler: (WKNavigationResponsePolicy) -> Unit) in the WKNavigationDelegate to also publish the response HTTP Status code.
Since I do not need the Desktop target currently, I have not implemented it for Desktop.

Unfortunately, there is an inconsistency between iOS and Android, in that the onReceivedHttpError Method on Android only is called when an error occurs and I have not yet found a way to get all Http Status Codes that the Webview receives. On iOS however, the webview(...) function receives all Http Status codes the Webview receives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant