signalpoint / jDrupal

A JavaScript Library and API for Drupal Applications
http://jdrupal.tylerfrankenstein.com/
GNU General Public License v2.0
76 stars 38 forks source link

Catch error viewsLoad() #75

Open SebastianKempf opened 7 years ago

SebastianKempf commented 7 years ago

I implemented jDrupal in a Vue.js Application that I build with webpack and so far it works great. Now, I run into a problem and the solution might be easy but I did not find anything in the documentation or online: I am loading a view with jDrupal.viewsLoad() and it works fine as long as the User has permission to access the view. If he does not have permission nothing is displayed and an “Uncaught (in promise)” error ist log in the console. I was wondering how I can catch this error and eventually display an “Access Denied” message. Usually javascript Promises have a catch function but that does not seem to be the case with jDrupal.viewsLoad() or I am missing something.

signalpoint commented 7 years ago

@SebastianKempf thank you for pointing this out. It looks like viewsLoad() isn't watching for errors and never calls the reject, and I'd suspect that is why it is un-catchable. For reference, here's the src code that would need modifying to properly reject the Promise: https://github.com/signalpoint/jDrupal/blob/8.x-1.x/src/includes/views.inc.js#L57