code: public static boolean handleCommonError(Throwable ex, String action)
    {
      if(ex != null)
      {
        Throwable rootCause = ex;
        while(rootCause.getCause() != null)
        {
          rootCause = rootCause.getCause();
        }
  
        if(rootCause instanceof UniformInterfaceException)
        {
          UniformInterfaceException uniEx = (UniformInterfaceException) rootCause;
          
          if(uniEx.getResponse() != null)
          {
            if(uniEx.getResponse().getStatus() == 503)
            {
              // database connection error
              Notification n = new Notification(
                  "Can't execute " + (action == null ? "" : "\"" + action + "\"" ) 
                  + " action because database server is not responding.<br/>"
                  + "There might be too many users using this service right now.", 
                  Notification.Type.WARNING_MESSAGE);
              n.setDescription("<p><strong>Please try again later.</strong> If the error persists inform the administrator of this server.</p>"
                  + "<p>Click on this message to close it.</p>"
                  + "<p style=\"font-size:9pt;color:gray;\">Pinguin picture by Polar Cruises [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons</p>");
              n.setIcon(PINGUIN_IMAGE);
              n.setHtmlContentAllowed(true);
              n.setDelayMsec(15000);
             
              n.show(Page.getCurrent());
              
              return true;
            }
          }
         
        }
      }
      return false;
    }
docs: Handle common errors like database/service connection problems and display a unified
  error message.
  
  This will not log the exception, only display information to the user.
  
  @param ex
  @return True if error was handled, false otherwise.