> ## Documentation Index
> Fetch the complete documentation index at: https://docs-staging-docs-ia-custom-database-connections.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Handling for Custom Database Connections

> Learn more about error handling when using custom database connections.

You may receive errors from custom databases. You can also return errors from database action scripts for troubleshooting.

## Custom database error types

Database connections may return the following errors:

| Error                                                                               | Action Script     | Occurs when...                                                                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------------------------------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `new WrongUsernameOrPasswordError(`<br />`  <email or user_id>, <message>`<br />`)` | Login             | The user's credentials are invalid. The [Log Event Type Codes](/docs/deploy-monitor/logs/log-event-type-codes) are: <ul><li>`fu` (invalid username/email) with an empty string for `user_id`, if passed no arguments or a falsey first argument.</li> <li>`fp` (user exists, password invalid) with a `user_id` value of `auth0\|<first_argument>`, if passed a truthy first argument.</li> </ul> |
| `new ValidationError(`<br />`  <user_exists>, <message>`<br />`)`                   | Create            | The user already exists in your database.                                                                                                                                                                                                                                                                                                                                                         |
| `callback(<null>,<false>)`                                                          | Change Password   | The user's password was not updated.                                                                                                                                                                                                                                                                                                                                                              |
| `callback(<null>)`                                                                  | Get User          | The user is not found.                                                                                                                                                                                                                                                                                                                                                                            |
| `new UnauthorizedError(<message>)`                                                  | All login scripts | Something went wrong while trying to reach the database. Preferred way of communicating errors back from custom databases to front-end.                                                                                                                                                                                                                                                           |
| `new Error(<message>)`                                                              | All login scripts | Something went wrong while trying to reach the database.                                                                                                                                                                                                                                                                                                                                          |
| `error code: auth0_idp_error;` `user already exists`                                | Create            | Automatic migration to Auth0 is disabled and you attempt to create a user that already exists in your external user store or in Auth0.                                                                                                                                                                                                                                                            |
| `error code: auth0_idp_error;` `user already exists`                                | Delete            | Automatic migration to Auth0 is disabled and you attempt to delete a user with custom database scripts.<br /><br />Error could also manifest as "Error! There was a problem deleting `user@example.com`" or "Sandbox Error: Please implement the Delete script for this database connection"                                                                                                      |

## Return errors

You can return errors from database action scripts using [the `callback` function](/docs/authenticate/database-connections/custom-db/custom-database-connections-scripts#callback). For example:

```js wrap lines theme={null}
callback(new ValidationError('email-too-long', 'Email is too long.'));
```

If you use Lock, you can [customize the error messages](/docs/customize/login-pages/classic-login/customize-lock-error-messages) by adding them to the dictionary.

## Troubleshoot errors

Test the script using the **Try** button.

If you do not get the expected result or you receive an error, use [Actions Real-time Logs](/docs/customize/actions/actions-real-time-logs), use `console.log()` statements in your script, and try the connection again. The output of `console.log()` prints to the Actions Real-time Logs window.

You may experience errors using action scripts to import, create, or delete users. Use `console.logs` to verify the error is a result of using action scripts.
