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

> Describes how to handle errors and troubleshoot when using your database as an identity provider.

# Troubleshoot Custom Databases

You can use return errors resulting from your custom database connection for troubleshooting purposes. We will also cover some basic troubleshooting steps for your scripts.

## Types of errors

You may receive different types of errors from a database connection:

<table class="table">
  <thead>
    <tr>
      <th>Error</th>
      <th>Login Script</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>new WrongUsernameOrPasswordError(\<email or user\_id>, \<message>)</code></td>
      <td>Login</td>
      <td>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 <code>fu</code> event (invalid username/email) with an empty string for a <code>user\_id</code>. Providing a truthy first argument will result in the error being logged as an <code>fp</code> event (the user exists, but the password is invalid) with a <code>user\_id</code> value of <code>auth0|\<first argument></code>. To learn more, read <a href="/docs/deploy-monitor/logs/log-event-type-codes">Log Event Type Codes</a>.</td>
    </tr>

    <tr>
      <td><code>new ValidationError(\<user\_exists>, \<message>)</code></td>
      <td>Create</td>
      <td>Occurs when a user already exists in your database.</td>
    </tr>

    <tr>
      <td><code>callback(\<null>,\<false>)</code></td>
      <td>Change Password</td>
      <td>Occurs when the user's password was not updated.</td>
    </tr>

    <tr>
      <td><code>callback(\<null>)</code></td>
      <td>Get User</td>
      <td>Occurs when the user is not found.</td>
    </tr>

    <tr>
      <td><code>new UnauthorizedError(\<message>)</code></td>
      <td>All Login Scripts</td>
      <td>Occurs when something went wrong while trying to reach the database. Preferred way of communicating errors back from custom databases to front-end.</td>
    </tr>

    <tr>
      <td><code>new Error(\<message>)</code></td>
      <td>All Login Scripts</td>
      <td>Occurs when something went wrong while trying to reach the database.</td>
    </tr>

    <tr>
      <td><code>error code: auth0\_idp\_error; user already exists</code></td>
      <td>Create</td>
      <td>Occurs in legacy identity store when you attempt to create a user that already exists in your legacy identity store or in Auth0.</td>
    </tr>

    <tr>
      <td><code>error code: auth0\_idp\_error; user already exists</code></td>
      <td>Delete</td>
      <td>Occurs in legacy identity store when you attempt to delete a user with custom database scripts. Error could also manifest as <code>Error! There was a problem deleting [user@example.com](mailto:user@example.com)</code> or <code>Sandbox Error: Please implement the Delete script for this database connection at [https://manage.auth0.com/#/connections/database](https://manage.auth0.com/#/connections/database)</code>.</td>
    </tr>
  </tbody>
</table>

## Return errors

To return an error, call the **callback** function while passing **error** as the first parameter:

```js lines
callback(error);
```

Example:

```js wrap lines
callback(new ValidationError('email-too-long', 'Email is too long.'));
```

### Returning errors when using Lock

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

## Troubleshooting errors

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

If you do not get the expected result or you receive an error, install the [Real-time Webtask Logs extension](/docs/customize/extensions/real-time-webtask-logs), use `console.log()` statements in your script, and try the connection again. The output of `console.log()` will print to the Real-time Webtask 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).
