Use Error Codes for API result

Hi there,

I’m tying Piwik into a Python/Django-based Webapp and therefore need to extend the Python wrapper from (no Github-fork avaible yet).
While adding error handling I realized I have to rely on the error message to tell the different errors apart. This means if there’s a typo in an error message I have to anticipate and the fixing of this relied-on typo breaks the API-wrapper.
The introduction of additional error codes ({result == ‘error’, message, errorcode} instead of {result == ‘error’, message}) would solve this problem.

SitesManager.addSite() returns “{‘message’: “You can’t access this resource as it requires a ‘superuser’ access.”, ‘result’: ‘error’}” (here in form of a string-represented Python-dictionary). If it would return “{‘message’: “You can’t access this resource as it requires a ‘superuser’ access.”, ‘result’: ‘error’, errorcode = 403}” one could simply check for the errorcode without relying on the error message.

Also it opens the possibility of localizing the API’s error messages because the error code would be sufficient to identify the reported problem.

Best regards

Agreed. Error codes are much easier to work with. +1