> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-docs-event-stream-action-templates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Troubleshoot Custom Databases

> How to handle errors and troubleshoot when using your own database as an identity provider.

You may receive errors from custom dataabaseses. You can also return errors from your custom database connection action scripts for troubleshooting.

## Custom database error types

Database connections may return the following errors:

| Error                                                                               | Login Script      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------------------------------------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `new WrongUsernameOrPasswordError(`<br />`  <email or user_id>, <message>`<br />`)` | Login             | Occurs when the user's credentials are invalid. Passing no arguments or a falsey first argument will result in the error being logged as an `fu` event (invalid username/email) with an empty string for a `user_id`. Providing a truthy first argument will result in the error being logged as an `fp` event (the user exists, but the password is invalid) with a `user_id` value of `auth0\|<first_argument>`. To learn more, read [Log Event Type Codes](/docs/deploy-monitor/logs/log-event-type-codes). |
| `new ValidationError(`<br />`  <user_exists>, <message>`<br />`)`                   | Create            | Occurs when a user already exists in your database.                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `callback(<null>,<false>)`                                                          | Change Password   | Occurs when the user's password was not updated.                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `callback(<null>)`                                                                  | Get User          | Occurs when the user is not found.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `new UnauthorizedError(<message>)`                                                  | All Login Scripts | Occurs when 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 | Occurs when something went wrong while trying to reach the database.                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `error code: auth0_idp_error;` `user already exists`                                | Create            | Occurs in legacy identity store when you attempt to create a user that already exists in your legacy identity store or in Auth0.                                                                                                                                                                                                                                                                                                                                                                               |
| `error code: auth0_idp_error;` `user already exists`                                | Delete            | Occurs in legacy identity store when you attempt to delete a user with custom database scripts. 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 at `https://manage.auth0.com/#/connections/database`".                                                                                                                                                                                |

## Return errors

To return an error, call the `callback()` function and pass `error` as the first parameter:

```js lines theme={null}
callback(error);
```

For example:

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

### Return errors when using Lock

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. To learn more, read [Custom Database Action Script Templates](/docs/authenticate/database-connections/custom-db/templates).
