Skip to content
Jeff Johns edited this page Jan 31, 2014 · 13 revisions

We return errors in two different methods. For the main application (marks, labels, tags, etc) we return an errors array with a list of error numbers and messages. Below are a list of errors for both the main application and supplementary actions.

Main Application

Number Message Notes
1 Mark could not be archived. Mark errors have reserved error numbers from 1 to 29.
2 No Marks Found. -
3 Mark could not be updated. -
4 Mark with this id could not be found for this account. -
5 Mark could not be restored. -
6 Could not add mark. -
30 No `label_id` was found. Label errors have reserved error numbers from 30 to 59.
31 No label found using this label_id for your account. -
32 No labels found for your account. -
33 This type of label could not be found. -
34 Label already exists for this account. -
35 No options found to update for this label. -
36 Label could not be created. -
37 You do not have access to create a system level label. -
38 Label already exists for this account. -
39 Label could not be updated. -
60 No tags found. Tag errors have reserved error numbers from 60 to 89.
61 No tag provided. -
62 Tag could not be added. -
600 Security token is invalid. System errors have reserved error numbers from 600 to 699.
601 Internal Error -
602 Validation Errors If you get this error the message will be an array of errors. We return multiple validation errors if found.

How to set an error in the application

It's easy to set an error. Simply reference this list, if the error doesn't fit add a new one to the App Configuration File. After that you can call the formatError helper and send the correct error number. It will return an array with the key being the error number and value being the error message.

Example

$this->data['errors'] = formatErrors(100);

// $this->data['errors'] would be an array that looks like this
array(
    100 => 'Security token is invalid.'
);

Doing this will allow you to keep your error messages in one place and fix them once.

Supplementary actions

For actions like simple ajax requests to update a password, email address or reset a password we use a simplified error report. When you get your JSON response there will always be a success key. It will be a boolean set to true or false. If false the action failed, if true you are good-to-go. If false there will also always be a message key returned and the value will be the error message.

On success equals true if data is to be returned it will be provided in the form needed. Most times when success is equal to true, it will be the only only key/value returned.

Error Sample

{
    'success': false,
    'message': 'The reason your request failed.'
}

Success Sample - Simplified

{
    'success': true
}

Success Sample - With Data Returned for getting a token

{
    'success': true,
    'token': 'q234asdfq345asdfaw45fdsEDET'
}