# Catch exception

The Catch Exception Action Node is used to execute an action when an error occurs.

When an error occurs in an action node, normal execution of the action will stop, and Appfarm will look for a Catch Exception Action Node. It will first look downward on the same level, then go up one level to look for it there (top-down), and so on. When it finds a catch block that meets the criteria of the error, the catch will execute whatever is defined inside it and then resume execution starting with the node directly after the catch (unless you use end execution or some other flow-changing action).

## Settings

### Catch All

If selected, all types of errors will trigger the execution of the action nodes inside the action.

### Execution Types

If Catch All is not selected, you need to define the execution type(s) that shall be caught. Four different options are available, and have a set of different properties.

#### Delete Constraint Exception

Used when there's a Delete Rule on a relation in the database, and the user tries to delete a parent. As long as objects in an object class have reference to a remote object class, deletions of referenced objects will not be allowed, i.e., if objects in the Project object class reference a Person object, it will not be possible to delete that Person object.

#### Web Request Error

Used when a web request returns an error, i.e., 400 or 500 error codes. If you don't want the action node to catch all exceptions, you might define specific HTTP Error Codes to be caught by the action node.

#### Custom Exception

Used when a Throw Exception Action Node returns an error. If you don't want the action node to catch all custom exceptions, you can define specific error codes that should be caught by the action node.

#### Defined errors

Used when Appfarm returns an error. Only the error codes you define will be caught by the action node. Relevant Appfarm error codes are grouped below.

**Login ticket errors**

<table><thead><tr><th>Code</th><th width="224.81817626953125">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>10400</td><td>InvalidTokenError</td><td>400</td><td>Invalid token provided</td></tr><tr><td>10403</td><td>UserValidationError</td><td>403</td><td>Unauthorized</td></tr><tr><td>10410</td><td>LoginTicketNotFoundError</td><td>—</td><td>Unable to find ticket from token</td></tr><tr><td>10440</td><td>ExpiredLoginTicketError</td><td>—</td><td>Token expired</td></tr><tr><td>10500</td><td>InvalidLoginTicketDataError</td><td>—</td><td>Invalid data in Login Ticket</td></tr></tbody></table>

**Auth errors**

<table><thead><tr><th>Code</th><th width="258.45452880859375">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>11002</td><td>GoogleUserNotFoundError</td><td>401</td><td>Unable to find user connected to Google Account</td></tr><tr><td>11005</td><td>UserAccountNotFound</td><td>404</td><td>Unable to find Appfarm User Account</td></tr><tr><td>11010</td><td>MissingOtpReferenceError</td><td>403</td><td>Cannot login this device with one time password</td></tr><tr><td>11011</td><td>ExpiredOtpReferenceError</td><td>403</td><td>One time password has expired</td></tr><tr><td>11012</td><td>TooManyOtpTriesError</td><td>403</td><td>Too many retries</td></tr><tr><td>11013</td><td>InvalidPinError</td><td>401</td><td>Invalid PIN</td></tr><tr><td>11014</td><td>UserAccessDisabled</td><td>403</td><td>User is disabled</td></tr><tr><td>11040</td><td>AnonymousAppAccessError</td><td>403</td><td>Anonymous application access is not enabled</td></tr><tr><td>11041</td><td>LoginMetodDisabledError</td><td>403</td><td>Tried to use a disabled login method</td></tr><tr><td>11401</td><td>AuthenticationError</td><td>401</td><td>Authentication required</td></tr><tr><td>11403</td><td>AuthorizationError</td><td>403</td><td>User does not have sufficient permissions</td></tr><tr><td>11404</td><td>EnvironmentAuthorizationError</td><td>403</td><td>Operation not allowed from current environment</td></tr><tr><td>11500</td><td>InternalError</td><td>500</td><td>Internal error</td></tr></tbody></table>

**User errors**

| Code  | Name                    | HTTP | Description                       |
| ----- | ----------------------- | ---- | --------------------------------- |
| 13005 | MultipleUsersFoundError | 500  | Found more than one matching user |

**Generic errors**

<table><thead><tr><th>Code</th><th width="223">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>14002</td><td>AmpServerError</td><td>500</td><td>Unknown AMP server error</td></tr><tr><td>14003</td><td>NotImplementedError</td><td>500</td><td>Feature not implemented</td></tr><tr><td>14004</td><td>NotSupportedError</td><td>500</td><td>Feature not supported</td></tr><tr><td>14005</td><td>InputSanitationError</td><td>400</td><td>User input failed sanitation check</td></tr><tr><td>14006</td><td>ApiRequestError</td><td>500</td><td>Call to API failed</td></tr><tr><td>14007</td><td>UserAccountAlreadyExistException</td><td>409</td><td>User already in current solution</td></tr><tr><td>14008</td><td>ResourceGoneError</td><td>410</td><td>Resource is no longer available</td></tr><tr><td>14009</td><td>QuotaExceededException</td><td>422</td><td>Quota exceeded</td></tr><tr><td>14010</td><td>InvalidOperationError</td><td>400</td><td>Invalid operation</td></tr><tr><td>14011</td><td>NotEnabledError</td><td>403</td><td>Feature not enabled</td></tr><tr><td>14012</td><td>DeploymentConflictError</td><td>409</td><td>Cannot deploy due to conflicts</td></tr><tr><td>14400</td><td>InvalidEmailError</td><td>400</td><td>Invalid email address</td></tr><tr><td>14403</td><td>ForbiddenError</td><td>403</td><td>Forbidden</td></tr><tr><td>14404</td><td>ResourceNotFoundError</td><td>404</td><td>Resource not found</td></tr><tr><td>14408</td><td>TimeoutError</td><td>408</td><td>Request timeout</td></tr><tr><td>14900</td><td>InputValidationError</td><td>400</td><td>Invalid input data</td></tr><tr><td>14901</td><td>DataTypeError</td><td>400</td><td>Invalid datatype error</td></tr><tr><td>14902</td><td>RequiredDataError</td><td>400</td><td>Data cannot be nil</td></tr></tbody></table>

**AMP protocol errors**

<table><thead><tr><th>Code</th><th width="224.81817626953125">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>15002</td><td>AmpMessageError</td><td>400</td><td>Unknown AMP message error</td></tr><tr><td>15003</td><td>AmpProtocolError</td><td>406</td><td>Protocol error</td></tr><tr><td>15004</td><td>ServerRestartException</td><td>400</td><td>Server is restarting</td></tr></tbody></table>

**Model / function errors**

<table><thead><tr><th>Code</th><th width="244.81817626953125">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>16001</td><td>UnexpectedDataTypeError</td><td>500</td><td>Unexpected datatype returned from function</td></tr><tr><td>16002</td><td>FunctionEvalError</td><td>500</td><td>Custom function value failed to evaluate</td></tr><tr><td>16003</td><td>FunctionEvalTimeoutError</td><td>500</td><td>Eval timeout — function took too long</td></tr><tr><td>16500</td><td>ModelParsingError</td><td>500</td><td>Failed to parse model</td></tr></tbody></table>

**Custom and web request errors**

<table><thead><tr><th>Code</th><th width="258.45452880859375">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>17001</td><td>AppfarmCustomException</td><td>500</td><td>Custom exception thrown from a Throw Exception action node</td></tr><tr><td>17003</td><td>WebRequestException</td><td>500</td><td>Web request failed</td></tr><tr><td>17004</td><td>GetUserMediaNotAllowedError</td><td>500</td><td>Access to a media device was denied</td></tr><tr><td>17005</td><td>WebRequestTimeoutException</td><td>0</td><td>Web request timed out</td></tr><tr><td>17006</td><td>WebRequestAbortedException</td><td>0</td><td>Web request was aborted</td></tr></tbody></table>

**API service errors**

<table><thead><tr><th>Code</th><th width="228.45458984375">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>31403</td><td>ActionNodeFailedError</td><td>400</td><td>Action Node Failed</td></tr><tr><td>31500</td><td>JobConcurrencyError</td><td>500</td><td>Cannot run multiple instances of job</td></tr><tr><td>31501</td><td>ActionNotFoundError</td><td>500</td><td>Unable to find action</td></tr></tbody></table>

**Client service errors**

| Code  | Name                  | HTTP | Description           |
| ----- | --------------------- | ---- | --------------------- |
| 32001 | AppNotActiveError     | 400  | App is not set active |
| 32002 | ClientOutOfSyncError  | 400  | Client Out of Sync    |
| 32003 | UnknownOperationError | 500  | Unknown Operation     |

**Data service errors**

<table><thead><tr><th width="87.90908813476562">Code</th><th width="283.90911865234375">Name</th><th width="98.36358642578125">HTTP</th><th>Description</th></tr></thead><tbody><tr><td>34002</td><td>UniquenessConstraintError</td><td>500</td><td>Uniqueness constraint violated</td></tr><tr><td>34003</td><td>MissingRequiredFieldsError</td><td>500</td><td>Required fields missing</td></tr><tr><td>34004</td><td>InsufficientCreatePermissionError</td><td>403</td><td>Insufficient create permission</td></tr><tr><td>34005</td><td>InsufficientAggregatePermissionError</td><td>403</td><td>Insufficient aggregate permission</td></tr><tr><td>34006</td><td>InsufficientUpdatePermissionError</td><td>403</td><td>Insufficient update permission</td></tr><tr><td>34007</td><td>InsufficientDeletePermissionError</td><td>403</td><td>Insufficient delete permission</td></tr><tr><td>34008</td><td>UpdateReadOnlyError</td><td>403</td><td>Attempted to update read-only field</td></tr><tr><td>34009</td><td>UpdateObjectError</td><td>500</td><td>Update object failed</td></tr><tr><td>34010</td><td>PersistError</td><td>500</td><td>Persist failed</td></tr><tr><td>34011</td><td>DeleteConstraintException</td><td>500</td><td>Unable to delete object (child references exist)</td></tr><tr><td>34012</td><td>PropertyValidationError</td><td>400</td><td>Property validation failed</td></tr><tr><td>34013</td><td>ConflictError</td><td>409</td><td>Conflict</td></tr><tr><td>34014</td><td>InsufficientReadPermissionError</td><td>403</td><td>Insufficient read permission</td></tr><tr><td>34015</td><td>BadRequestError</td><td>400</td><td>Bad request</td></tr><tr><td>34016</td><td>DocumentLimitExceededError</td><td>400</td><td>Document limit exceeded</td></tr></tbody></table>

**Messaging errors**

<table><thead><tr><th width="99.3636474609375">Code</th><th width="281.18182373046875">Name</th><th>HTTP</th><th>Description</th></tr></thead><tbody><tr><td>35001</td><td>SmsDisabledException</td><td>—</td><td>SMS is disabled</td></tr><tr><td>35002</td><td>DailyQuotaExceededException</td><td>—</td><td>Daily quota exceeded</td></tr><tr><td>35003</td><td>MonthlyQuotaExceededException</td><td>—</td><td>Monthly quota exceeded</td></tr></tbody></table>

### Result mapping

Result mapping might be used to map error data to Data Sources. The following data is available:

| Key                | Data                        |
| ------------------ | --------------------------- |
| **httpStatusCode** | Error code                  |
| **code**           | Internal Appfarm error code |
| **name**           | Error name                  |
| **message**        | Error message               |
| **body**           | Web Request response data   |

The data is returned as a JSON object, and body data can be mapped by setting RootPath to `body.theKeyYouWant`.

```
{
    httpStatusCode: integer,
    code: integer,
    name: String,
    message: String,
    body: {}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appfarm.io/library/action-nodes/catch-exception.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
