Actual Behavior:
What is the issue? * When calling $mdDialog.show() and the user press cancel, a message is shown in the console: "Possibly unhandled rejection: undefined"What is the expected behavior?app.config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false);
}]);
$mdDialog.show({...})
.then(confirmUserAction)
.catch(() => {}); // or angular.noop
What are your thoughts?
Thanks
CodePen (or steps to reproduce the issue): *
Details:Angular Versions: *
Angular Version: 1.6.1Angular Material Version: 1.1.1Additional Information:
Browser Type: * ChromeBrowser Version: * 55OS: * MacOSStack Traces:I think ultimately Solution 2 will be the best way to handle this. I'll be using Solution 4 until we have an answer from the Angular Material team as to weather or not they want to do something like Solution 2. Thanks for posting this by the way!
I agree that Solution 2 is probably the best way to handle this long term. Another option in the interim is something between 3 and 4-- monkey-patch the show() method in a run block rather than changing the global $qProvider or modifying every single use of $mdDialog.show().
Like:
app.run(['$mdDialog', ($mdDialog) => {
let original = $mdDialog.show;
$mdDialog.show = (...args) => original(...args).catch(() => {}); // or angular.noop
}]);
I haven't tested this fully. Obviously not ideal.
@keatonboyle I like your thinking. However, this causes the then(...) to always run, which, if cancel is pressed, isn't always a good idea. I've made the following modification, which throws a specific type of error. I've overridden $exceptionHandler to deal with this specific type of error:
module.run(function($mdDialog, $q){
let original = $mdDialog.show;
$mdDialog.show = (...args) => {
return original(...args).catch(() => { throw 'ignore' });
}
});
module.config(function($provide, HttpError){
$provide.decorator('$exceptionHandler', function($delegate, $injector){
return function(exception, cause){
if(exception === 'Possibly unhandled rejection: ignore') return;
$delegate(exception, cause);
}
});
});
+1
This is related to https://github.com/angular/material/issues/11181.
We have no plans to implement any major changes like Solution 2 would require.
Solution 4 is the recommended approach (along with possibly doing something useful in the catch block).
For reference on Solution 3, you can find the docs for $qProvider.errorOnUnhandledRejections here.
In addition to solution 3, dont use noop or any complete hiding solution:
$mdDialog.show({...})
.then(confirmUserAction)
.catch(function (err) {
if (err) {
console.error(err);
}
});
I believe that the confusion here has been settled and the approaches above are sufficient.
Most helpful comment
I think ultimately Solution 2 will be the best way to handle this. I'll be using Solution 4 until we have an answer from the Angular Material team as to weather or not they want to do something like Solution 2. Thanks for posting this by the way!