# 6. Handling Errors

### Handling Errors

HAT JS error response:

```javascript
{
  cause: string,   // The cause of the error.
  message: string, // The message of the error.
  status: number   // When the cause is HAT_API_EXCEPTION you can handle the HTTP response code.
}
```

**Error Codes:**

| Cause                     | Message                                 | Error definitions                                |
| ------------------------- | --------------------------------------- | ------------------------------------------------ |
| HAT\_CLIENT\_VALIDATION   | HAT\_DOMAIN\_IS\_UNDEFINED              | `hatDomain` parameter is required                |
| HAT\_CLIENT\_VALIDATION   | RECORD\_IDS\_MISSING                    | `recordsIds` array parameter is empty or null    |
| HAT\_CLIENT\_VALIDATION   | APPLICATION\_NOT\_SUPPORTED             | application is not supported                     |
| HAT\_CLIENT\_VALIDATION   | NOT\_AUTHENTICATED                      | client is not authenticated                      |
| HAT\_TOKEN\_VALIDATION    | HAT\_TOKEN\_IS\_NOT\_VALID\_OR\_EXPIRED | Authentication token has expired or is not valid |
| HAT\_TOKEN\_VALIDATION    | HAT\_TOKEN\_IS\_UNDEFINED               | Authentication token is undefined                |
| HAT\_TOKEN\_VALIDATION    | HAT\_TOKEN\_FAILED\_TO\_DECODE          | Authentication token has failed to decode        |
| HAT\_API\_EXCEPTION       | HTTP\_RESPONSE\_FAILED                  | HTTP response failed                             |
| HAT\_FILE\_API\_EXCEPTION | FILE\_IS\_UNDEFINED                     | File parameter is undefined                      |
| HAT\_FILE\_API\_EXCEPTION | FAILED\_TO\_FETCH\_METADATA             | Failed to fetch HAT File metadata                |
| HAT\_FILE\_API\_EXCEPTION | FILE\_FAILED\_TO\_UPLOAD                | Failed to upload the file to AWS                 |


---

# 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.dataswyft.com/build/advanced-topics/pda-authentication/password-management/tutorials/data-api/6.-handling-errors.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.
