Reputation: 643
I have been into Aurelia development but took break for two months. Now I have started a new project in it and I am encountering an unknown issue when trying to use http-fetch-client
.
Console shows:
aurelia-fetch-client.js?a909:199 OPTIONS http://url.com/api/login net::ERR_CONNECTION_REFUSED
index.js?07f7:248 Possible Unhandled Promise Rejection: TypeError: Failed to fetch
Network tab shows:
Request URL: http://url.com/api/login
Referrer Policy: no-referrer-when-downgrade
To my surprise, my previous project (that was executing fetch client request successfully two months ago) is also showing this error now. Can anyone give insight over this issue? Why am I encountering this?
Upvotes: 1
Views: 428
Reputation: 5203
It sounds like you're doing async/await, and you haven't wrapped your await
call in a try/catch
.
Some versions of Aurelia use Bluebird as a Promise shim, and you can use their global rejection events to deal with those problems.
Here's what that looks like.
// NOTE: event name is all lower case as per DOM convention
window.addEventListener("unhandledrejection", function(e) {
// NOTE: e.preventDefault() must be manually called to prevent the default
// action which is currently to log the stack trace to console.warn
e.preventDefault();
// NOTE: parameters are properties of the event detail property
var reason = e.detail.reason;
var promise = e.detail.promise;
// See Promise.onPossiblyUnhandledRejection for parameter documentation
});
// NOTE: event name is all lower case as per DOM convention
window.addEventListener("rejectionhandled", function(e) {
// NOTE: e.preventDefault() must be manually called prevent the default
// action which is currently unset (but might be set to something in the future)
e.preventDefault();
// NOTE: parameters are properties of the event detail property
var promise = e.detail.promise;
// See Promise.onUnhandledRejectionHandled for parameter documentation
});
Of course, you might be using a different Promise shim. But, ultimately, try/catch
is your answer.
Upvotes: 1