Which is the best method to use a global directive to manage and display error message?

Which is the best method to use s global directive to manage and display error message?

I see this Add server error messages to all views with directive but I wish to pass error message from a view without repeat code in every controller but passing data to a global directive or function.