CapacitorHttp Plugin error handling
See original GitHub issueBug Report
Plugin(s)
CapacitorHttp
Capacitor Version
@capacitor/core 4.4.0
Platform(s)
iOS
Current Behavior
iOS app freezes when CapacitorHttp throws an error. try and catch does not help. In my case it happens when I call a domain that does not exist. The console then shows “NSURLErrorDomain” and the app stops there.
Expected Behavior
There should be some possibility to handle the errors.
Code Reproduction
const options = { url: ‘https://wrongDomainXYZ.com’, method: ‘GET’, headers: { ‘Accept’:’ /‘, ‘User-Agent’:’’ }, params: {}, responseType: ‘text’, disableRedirects: false };
let response = {};
try {
response = await window.Capacitor.Plugins.CapacitorHttp.request(options);
console.log(response);
} catch (error) {
console.log(error);
}
Other Technical Details
Additional Context
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
capacitor community/http handle errors - Stack Overflow
Install Latest https://github.com/capacitor-community/http plugin. use function public async login(formData: AuthLoginFormData){ let options ...
Read more >Capacitor community http handle errors - Ionic Forum
In my case, I manually throw the errors in the response: return (Http.request(options).then((response) => ( handleResponse(response) )).catch(( ...
Read more >Capacitor Http Plugin API
The Capacitor Http API provides native http support via patching fetch and XMLHttpRequest to use native libraries. It also provides helper methods for...
Read more >How to make API calls in Ionic Capacitor Apps - Medium
But we'll see that Capacitor can use Cordova plugins as well. REST API call issues. Before we explore the options to do http...
Read more >@capacitor-community/http - npm
A native HTTP plugin for CORS-free requests and file transfers. Latest version: 1.4.1, last published: a year ago.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue here. It has been fixed on the original @capacitor-community/http project : https://github.com/mrahn24/http/commit/da0742fde037e34008a5c86a176a1c33b888bc02
I’ve submitted a PR https://github.com/ionic-team/capacitor/pull/6033
Thanks, I’ve created a sample app from the zip since it contained an app inside the app and the changes were made in the build folder, so they got overridden on npm run build. https://github.com/jcesarmobile/http-errors
but I could reproduce on iOS
also added a fetch call to compare both behaviors