2

Real life scenario for a context: A two instances of a JS library, each from different version are being loaded. Since the library do not keep backward compatibility someone code will probably fail, either the code using the first instance or the code using the second.

For graceful degradation I am going to wrap the problematic code in a try { } catch {} block to have only my code fail instead of the whole page.

The question is really how do I report to the user that there is a problem. logging to console is fine once you need debuging data but it is not user friendly. Lets assume for the sake of this question that we are talking about traditional admin side only.

1

You could probably make use of WP built-in notices and create one using JavaScript.

jQuery(function($){
  $('.wrap > h1').after('<div class="error notice"><p>' + 'Your error message' + '</p></div>');
});
  • 1
    Could you elaborate how this works, please and thank you. – Caspar Apr 22 '16 at 21:28
  • 1
    Well, that code should be under your exception catch. – Zlatev Apr 23 '16 at 7:17
  • Accepting although I didn't actually got to implement as I decided that in my case, which is very widget related, it is just not good enough, – Mark Kaplun Apr 25 '16 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.