CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Improving the error messages handling
Pages: [1]

Author Topic: Improving the error messages handling  (Read 613 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Improving the error messages handling
June 03, 2011, 03:40:00 am
Hi,

On the of the issue we have is that when you have an error, you need to parse error_message to handle it. And based on my experience with unit testing, not the most reliable way of testing

We can provide an additional optional param to civicrm_api3_create_error, and I have started providing an error_type when I was working on the generic getsingle action

so
civicrm_api3_create_error("Expected one $entity but found " .$result['count'], array ('error_type' => 'too_many_results', 'count'=>$result['count']))

will generate:
Code: [Select]
{
"is_error":1,
"error_message":"Expected one Contact but found 4",
"error_type":"too_many_results",
"count":4
}

Suggested syntax: set "error_type", value only lower case string and underscore.

I'd suggest to test on error_type (and other optional fields returned if needed) instead of parsing the error_message (that is made to be displayed), eg in phpunit too

What do you think ?

X+


-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Improving the error messages handling
June 03, 2011, 09:25:15 am
Hi X.,
I think it is a good idea, the error messaging definitely needs improving and the error_type seems like a good way to make a start. We need to come up with a set of error_types that are short and make sense, like:
mandatory_fields_missing
too_many_results
params_not_array
etc. etc.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Improving the error messages handling
June 03, 2011, 09:43:08 am
I'll extends the exception class to make use of that for the "generic" errors.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Improving the error messages handling

This forum was archived on 2017-11-26.