diff --git a/modules/ldapstatus/www/index.php b/modules/ldapstatus/www/index.php
index ef8064706116381566e1ddac57d4670257fd1189..2ddd5779c5f98d5249fd55e5353d0eed3935a88a 100644
--- a/modules/ldapstatus/www/index.php
+++ b/modules/ldapstatus/www/index.php
@@ -11,6 +11,31 @@ if (!$session->isValid('login-admin') ) {
 }
 
 
+function myErrorHandler($errno, $errstr, $errfile, $errline) {
+
+    switch ($errno) {
+    case E_USER_ERROR:
+    	SimpleSAML_Logger::error('PHP_ERROR   : [' . $errno . '] ' . $errstr . '. Fatal error on line ' . $errline . ' in file ' . $errfile);
+    	break;
+
+    case E_USER_WARNING:
+    	SimpleSAML_Logger::error('PHP_WARNING : [' . $errno . '] ' . $errstr . '. Warning on line ' . $errline . ' in file ' . $errfile);
+    	break;
+
+    case E_USER_NOTICE:
+    	SimpleSAML_Logger::error('PHP_WARNING : [' . $errno . '] ' . $errstr . '. Warning on line ' . $errline . ' in file ' . $errfile);        
+    	break;
+
+    default:
+    	SimpleSAML_Logger::error('PHP_UNKNOWN : [' . $errno . '] ' . $errstr . '. Unknown error on line ' . $errline . ' in file ' . $errfile);        
+        break;
+    }
+
+    /* Don't execute PHP internal error handler */
+    return true;
+}
+$old_error_handler = set_error_handler("myErrorHandler");
+
 $ldapconfig = $config->copyFromBase('loginfeide', 'config-login-feide.php');
 $ldapStatusConfig = $config->copyFromBase('ldapstatus', 'module_ldapstatus.php');
 
@@ -126,8 +151,10 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 	// LDAP Connect
 	try {
 		$ldap = new SimpleSAML_Auth_LDAP($orgconfig['hostname'], (array_key_exists('enable_tls', $orgconfig) ? $orgconfig['enable_tls'] : FALSE), $debug);
+		if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError());
 		$results[$orgkey]['connect'] = array(TRUE,NULL);
 	} catch (Exception $e) {
+		SimpleSAML_Logger::debug('ldapstatus: Connect error() [' .$orgkey . ']: ' . $e->getMessage());
 		$results[$orgkey]['connect'] = array(FALSE,$e->getMessage());
 		$results[$orgkey]['time'] = microtime(TRUE) - $previous;
 		continue;
@@ -136,7 +163,9 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 	// Bind as admin user
 	if (isset($orgconfig['adminUser'])) {
 		try {
+			SimpleSAML_Logger::debug('ldapstatus: Admin bind() [' .$orgkey . ']');
 			$success = $ldap->bind($orgconfig['adminUser'], $orgconfig['adminPassword']);
+			if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError());
 			if ($success) {
 				$results[$orgkey]['adminBind'] = array(TRUE,NULL);
 			} else {
@@ -154,6 +183,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 	// Search for bogus user
 	try {
 		$dn = $ldap->searchfordn($orgconfig['searchbase'], 'eduPersonPrincipalName', $eppn, TRUE);
+		if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError());
 		$results[$orgkey]['ldapSearchBogus'] = array(TRUE,NULL);
 	} catch (Exception $e) {
 		$results[$orgkey]['ldapSearchBogus'] = array(FALSE,$e->getMessage());
@@ -168,6 +198,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 		// Try to search for DN of test account
 		try {
 			$dn = $ldap->searchfordn($orgconfig['searchbase'], 'eduPersonPrincipalName', $orgconfig['testUser']);
+			if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError());
 			$results[$orgkey]['ldapSearchTestUser'] = array(TRUE,NULL);
 		} catch (Exception $e) {
 			$results[$orgkey]['ldapSearchTestUser'] = array(FALSE,$e->getMessage());
@@ -186,6 +217,7 @@ foreach ($orgs AS $orgkey => $orgconfig) {
 
 		try {
 			$attributes = $ldap->getAttributes($dn, $orgconfig['attributes'], $ldapconfig->getValue('attributesize.max', NULL));
+			if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError());
 			$results[$orgkey]['ldapGetAttributesTestUser'] = array(TRUE,NULL);
 		} catch(Exception $e) {
 			$results[$orgkey]['ldapGetAttributesTestUser'] = array(FALSE,$e->getMessage());