question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CapacitorHttp Plugin error handling

See original GitHub issue

Bug 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:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
archibald-picqcommented, Oct 27, 2022
1reaction
jcesarmobilecommented, Oct 25, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found