From c56bd7903e0d88908ddfbef61de17b5d8540e1ac Mon Sep 17 00:00:00 2001 From: Xavier Dutoit Date: Fri, 1 Mar 2013 12:51:56 +0100 Subject: [PATCH] CRM-11926 add a better error handling for db errors in the api --- api/api.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/api.php b/api/api.php index c61a955857..16b3e30391 100644 --- a/api/api.php +++ b/api/api.php @@ -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(); } -- 2.25.1