---
schema_version: "1"
id: 019dcf4c9de02c89063c2b23ea65cf684893263241d3eff40ec6e9ee81e9da85
title: Create Custom Error Messages in the Login Discovery Handler
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/external_identity_login_discovery_custom_error_exception.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.external_identity_login_discovery_custom_error_exception.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 52450fdcc659e06ff37ae68e62659d2907c0934534636f999c49339411aee0e0
description: If a user makes a mistake when trying to log in to your site, the Apex handler displays a generic error message. You can customize the error message that appears on the login page using the Auth.DiscoveryCustomErrorException exception.
products:
  - Security
  - Cross Cloud
release: "264"
---
# Create Custom Error Messages in the Login Discovery Handler

If a user makes a mistake when trying to log in to your site, the Apex handler displays a generic error message. You can customize the error message that appears on the login page using the `Auth.DiscoveryCustomErrorException` exception.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d49727e75">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d49727e75 ">To access Experience Workspaces:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d49727e75 ">
              <ul>
                <li>Access Experience Management OR Manage Experiences OR Create and Set Up
                  Experiences</li>

                <li>AND is a member of the Experience Cloud site</li>

              </ul>
            </td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d49727e75 ">To create and edit Visualforce pages:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d49727e75 ">Customize Application</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d49727e75 ">To edit Apex classes:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d49727e75 ">
              <ul>
                <li>Author Apex</li>

                <li> AND Customize Application</li>

              </ul>
            </td>

          </tr>
        </tbody>
      </table>

1. From Setup, in the Quick Find box, enter Apex, and then select **Apex Classes**.
2. From the list of Apex classes, find the class that implements `Auth.LoginDiscoveryHandler`.
    
    You can find the name of the handlers on the Login & Registration page of the Administration workspace. If you haven’t renamed the handler, the name is similar to `AutocreatedDiscLoginHandler1535677786093`.
3. To add the custom error message, edit the Apex class using the `Auth.DiscoveryCustomErrorException` exception.
    
    For example, `throw new Auth.DiscoveryCustomErrorException('Custom error message defined by the admin.')`.
4. (Optional) Instead of entering the custom error message in the Apex class, you can create the error message as a custom label.
    
    Custom labels are custom text values that can be translated to the user’s native language. In this example, `CustomError` is a custom label.
    
    `throw new Auth.DiscoveryCustomErrorException(Label.CustomError)`
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/images/icon_note.png)
    
    Note You create a custom error message from the Custom Labels Setup page. The error message can be up to 200 characters.

Login Discovery custom error messages appear on the login page.