CRM-11926 add a better error handling for db errors in the api