vendredi 11 mars 2016

Ember.js 2.x: Handling "Could not find component..." error thrown by component helper

I have need in my Ember.js app to render a different component based on some piece of data. I've set this up via the component helper, like so:

<article class='awesome-article'>
    {{component article-type}}
</article>

This works all fine and well, though naturally, if article-type attribute doesn't match the name of any component in the application (which may happen due to fat-fingering), it gives us a nice, explicit error message:

Uncaught Error: Assertion Failed: HTMLBars error: Could not find component named "nonexistent-component" (no component or template with that name was found)

This is also great, but now I've got a smaller problem: I'd like to gracefully handle this error in the application, but I can't seem to figure out how to either catch or prevent this error. I've tried adding an error action to the parent component, but it skips right past it.

How can I go about handling this? This is probably one of those "missing something obvious" things, but my Google-fu has failed me this time.




Aucun commentaire:

Enregistrer un commentaire