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

Http error callback #885

Merged
merged 2 commits into from
Sep 21, 2019

Conversation

hojason117
Copy link
Contributor

@hojason117 hojason117 commented Sep 20, 2019

Summary

This PR adds an onHttpError callback which notifies the host app that an error http status code is received.

After finishing the code I found out there's already a closed PR for this feature but it never get merged, so I figure I'll just mention it here and I've also addressed to most of the comments in that PR.
Http error callback (Catch http error statuscode) #558

It's useful to be able to get the error status code in the webview, so that we can have different error handlings based on the status code (e.g. refresh token on 401).

Requests for nested frames are filtered out, so onHttpError will only be called on the main frame.

The native event returned from this callback will contain:
statusCode: The http error status code.
description: Description of the error status code (only on Android).

Implementation:
iOS: decidePolicyForNavigationResponse
Android: onReceivedHttpError (introduced in API level 23)

Fixes #189
Fixes #807

Test Plan

What's required for testing (prerequisites)?

What are the steps to reproduce (after prerequisites)?

Compatibility

OS Implemented
iOS
Android ✅ (only on >= 6.0)

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I mentioned this change in CHANGELOG.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)

@Titozzz
Copy link
Collaborator

Titozzz commented Sep 20, 2019

What is the difference between that and onLoadingError ?

@hojason117
Copy link
Contributor Author

@Titozzz I assume you are talking about the onError callback. onError is called when the webview failed to load the content, usually means there's no internet connection. The error code in the onError callback is not an http status code, but something like this on iOS and this on Android.
On the other hand onHttpError catches the http error status code (e.g. 4xx, 5xx).

@Titozzz Titozzz merged commit 552472c into react-native-webview:master Sep 21, 2019
react-native-community-bot pushed a commit that referenced this pull request Sep 21, 2019
# [7.1.0](v7.0.7...v7.1.0) (2019-09-21)

### Bug Fixes

* **iOS:** Call dispatchViewManagerCommand with correct number of arguments ([#886](#886)) ([33f1ee3](33f1ee3))
* **iOS:** inconsistent backgroundColor ([#868](#868)) ([d25b20a](d25b20a))

### Features

* **iOS:** Allow custom CA to be used on webview requests ([#865](#865)) ([136fbd8](136fbd8))
* **new prop:** onHttpError callback ([#885](#885)) ([552472c](552472c))
@react-native-community-bot
Copy link
Collaborator

🎉 This PR is included in version 7.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Ryan007008 added a commit to joycastle/react-native-webview that referenced this pull request Oct 12, 2019
* master: (182 commits)
  chore(release): 7.2.5 [skip ci]
  fix(types): Make onContentProcessDidTerminate optional (react-native-webview#890)
  chore(release): 7.2.4 [skip ci]
  fix(android): Revert scroll update from react-native-webview#281 (react-native-webview#889)
  chore(release): 7.2.3 [skip ci]
  fix(iOS): Xcode issues and warnings (no functionality changes) (react-native-webview#860)
  chore(release): 7.2.2 [skip ci]
  fix(android): redirect and renderLoading issues (react-native-webview#548)
  chore(release): 7.2.1 [skip ci]
  fix(android): Filter extra onLoadProgress & add url event (react-native-webview#643)
  chore(release): 7.2.0 [skip ci]
  feat(iOS): Add callback for webViewWebContentProcessDidTerminate (react-native-webview#774)
  chore(release): 7.1.1 [skip ci]
  fix(Android): hardware acceleration issue (react-native-webview#854)
  chore(release): 7.1.0 [skip ci]
  feat(iOS): Allow custom CA to be used on webview requests (react-native-webview#865)
  feat(new prop): onHttpError callback (react-native-webview#885)
  fix(iOS): Call dispatchViewManagerCommand with correct number of arguments (react-native-webview#886)
  fix(iOS): inconsistent backgroundColor (react-native-webview#868)
  chore(release): 7.0.7 [skip ci]
  ...

# Conflicts:
#	android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
#	ios/RNCUIWebView.h
#	ios/RNCUIWebView.m
#	ios/RNCUIWebViewManager.m
#	ios/RNCWebView.h
#	ios/RNCWebView.m
#	ios/RNCWebViewManager.m
#	js/WebView.android.js
#	js/WebView.ios.js
#	js/WebViewTypes.js
#	typings/index.d.ts
phuongwd pushed a commit to phuongwd/react-native-webview that referenced this pull request Apr 29, 2020
phuongwd pushed a commit to phuongwd/react-native-webview that referenced this pull request Apr 29, 2020
# [7.1.0](react-native-webview/react-native-webview@v7.0.7...v7.1.0) (2019-09-21)

### Bug Fixes

* **iOS:** Call dispatchViewManagerCommand with correct number of arguments ([react-native-webview#886](react-native-webview#886)) ([33f1ee3](react-native-webview@33f1ee3))
* **iOS:** inconsistent backgroundColor ([react-native-webview#868](react-native-webview#868)) ([d25b20a](react-native-webview@d25b20a))

### Features

* **iOS:** Allow custom CA to be used on webview requests ([react-native-webview#865](react-native-webview#865)) ([136fbd8](react-native-webview@136fbd8))
* **new prop:** onHttpError callback ([react-native-webview#885](react-native-webview#885)) ([552472c](react-native-webview@552472c))
noproblem23 added a commit to noproblem23/react-native-webview that referenced this pull request Apr 18, 2023
# [7.1.0](react-native-webview/react-native-webview@v7.0.7...v7.1.0) (2019-09-21)

### Bug Fixes

* **iOS:** Call dispatchViewManagerCommand with correct number of arguments ([#886](react-native-webview/react-native-webview#886)) ([33f1ee3](react-native-webview/react-native-webview@33f1ee3))
* **iOS:** inconsistent backgroundColor ([#868](react-native-webview/react-native-webview#868)) ([d25b20a](react-native-webview/react-native-webview@d25b20a))

### Features

* **iOS:** Allow custom CA to be used on webview requests ([#865](react-native-webview/react-native-webview#865)) ([136fbd8](react-native-webview/react-native-webview@136fbd8))
* **new prop:** onHttpError callback ([#885](react-native-webview/react-native-webview#885)) ([552472c](react-native-webview/react-native-webview@552472c))
jaynilson added a commit to jaynilson/reactNative_service_USA that referenced this pull request Sep 11, 2024
# [7.1.0](react-native-webview/react-native-webview@v7.0.7...v7.1.0) (2019-09-21)

### Bug Fixes

* **iOS:** Call dispatchViewManagerCommand with correct number of arguments ([#886](react-native-webview/react-native-webview#886)) ([33f1ee3](react-native-webview/react-native-webview@33f1ee3))
* **iOS:** inconsistent backgroundColor ([#868](react-native-webview/react-native-webview#868)) ([d25b20a](react-native-webview/react-native-webview@d25b20a))

### Features

* **iOS:** Allow custom CA to be used on webview requests ([#865](react-native-webview/react-native-webview#865)) ([136fbd8](react-native-webview/react-native-webview@136fbd8))
* **new prop:** onHttpError callback ([#885](react-native-webview/react-native-webview#885)) ([552472c](react-native-webview/react-native-webview@552472c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check requested page network status and errors I hope listening to the loading fail (500 or 404 or 401 )
3 participants