How to JS-throw error in then() to be catched in catch()
See original GitHub issueI have a use case that is not easy to handle with AuraHandledExceptions alone. Before I query a lot of records in Apex I first count them. Depending on the resultCount I want the below JS code to eighter fire a new callback or throw the same type of error that an Apex side exception would have thrown. Why? So I can handle it with the same LAX catch.
Is that possible?
cmp.lax.enqueue("c.countResults")
.then((resultCount) => {
if(resultCount < 1000)
return cmp.lax.enqueue("c.queryData");
}
else {
// Throw error to be catched and display in below catch
}
})
.then((result) => {
...
})
.catch((e) => {
cmp.find("toast").toastError(e);
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
What if I use "throw" in "catch"? - javascript - Stack Overflow
The keyword throw is used to throw a error to the superior scope (who call the function for sample) passing the error on...
Read more >Promise.prototype.catch() - JavaScript - MDN Web Docs
Promise.prototype.catch(). The catch() method of a Promise object schedules a function to be called when the promise is rejected.
Read more >Error handling with promises - The Modern JavaScript Tutorial
In the task an error is thrown form inside the promise and promise is never settled neither with a resolve nor reject. The...
Read more >Using .then(), .catch(), .finally() to Handle Errors in Javascript ...
When a problem arises and is then handled, an “exception is thrown” by the Javascript interpreter. Javascript generates an object containing the details...
Read more >JavaScript Errors Try Catch Throw - W3Schools
JavaScript try and catch. The try statement allows you to define a block of code to be tested for errors while it is...
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 Free
Top 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
Works like a charm.
@rsoesemann I’ve completed this item 😃 Could you help me to test that on your side?
Here is feature branch with this particular change: https://github.com/ruslan-kurchenko/sfdc-lax/tree/feature/remove-aura-error-message-prefix