I have a module thats occasionally giving me an SQL error message. As the module is working fine and the fix is committed to the next release im leaving it for now.

The only problem is my client has seen the message. Can I hide error messages based on roles? I dont know how to recreate the error so its hard to test.

Thanks

Comments

theabacus’s picture

I would not recommend hiding all errors from users, since some errors are designed for them.

In the "error reporting" section of the admin (admin/settings/error-reporting) you can set PHP/MySQL errors to only write to log and not to display on screen. You can then check the log to see the errors that are occurring since it is hard to reproduce them...

jdln’s picture

Ok. I wish there way a way so just show errors to user 1 or by role.
Thanks

ari-meetai’s picture

There's a module somewhere that does exactly that. I regret I can't remember where... It won't be too difficult to code, though.

EDIT: here you have - http://drupal.org/project/msg2log < Merged into Drupal Tweaks

jdln’s picture

Thanks!

anoopjohn’s picture

You could also try http://drupal.org/project/disable_messages if hiding messages is all what you need.

mcdoolz’s picture

I've found a few threads, but https://drupal.org/node/905774#comment-3426866 got me rolling with a D6 solution; and I combined it with the is_admin code from the Seven theme.

function phptemplate_status_messages($display = NULL) {
    $output = '';
    global $user;
    $is_admin = in_array('admin', $user->roles);

    foreach (drupal_get_messages($display) as $type => $messages) {
      if (($type == 'error' && $is_admin > 0) || $type != 'error') {
        $output .= "<div class=\"messages $type\">\n";
        if (count($messages) > 1) {
          $output .= " <ul>\n";
          foreach ($messages as $message) {
            $output .= '  <li>'. $message ."</li>\n";
          }
          $output .= " </ul>\n";
        }
        else {
          $output .= $messages[0];
        }
        $output .= "</div>\n";
      }
    }
    return $output;
  }

Error messages are now shown only to admins.
If you don't know what to do, edit or create your template.php and paste this in.
Don't forget to rename phptemplate_ to your templatesname_.

-
Be the occasion.

mark_fullmer’s picture

This module achieves the original request in this thread: https://www.drupal.org/project/errorlevelpermission

markpape’s picture

thank you mark!