CRM-11926 add a better error handling for db errors in the api
authorXavier Dutoit <xavier@tttp.eu>
Fri, 1 Mar 2013 11:51:56 +0000 (12:51 +0100)
committerXavier Dutoit <xavier@tttp.eu>
Fri, 1 Mar 2013 13:08:30 +0000 (14:08 +0100)
api/api.php

index c61a9558578168cbaf7dd83fb41c537b10bba694..16b3e30391390a5f893b6982967b0599b58eb476 100644 (file)
@@ -107,8 +107,12 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
     if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
       return 0;
     }
+    $error = $e->getCause();
+    if ($error instanceof DB_Error) {
+      $data["error_code"] = DB::errorMessage($error->getCode());
+      $data["sql"] = $error->getDebugInfo();
+    }
     if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
-      $error = $e->getCause();
       $data['debug_info'] = $error->getUserInfo();
       $data['trace'] = $e->getTraceAsString();
     }