> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.generaltranslation.app/llms.txt
> Use this file to discover all available pages before exploring further.

# ロックのエラーメッセージをカスタマイズする

> ロックで表示されるエラーメッセージをカスタマイズします。

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        let processedChildren = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          processedChildren = processedChildren.replace(new RegExp(key, "g"), value);
        }
        setProcessedChildren(processedChildren);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
      {processedChildren}
    </CodeBlock>;
};

特定の状況で表示されるエラーメッセージは、`languageDictionary`オプションを提供すると、カスタマイズできるようになります。カスタマイズに使用可能な`languageDictionary`フィールドの全リストは、GitHubリポジトリにある[ロック用の英語辞書ファイル](https://github.com/auth0/lock/blob/master/src/i18n/en.js)に含まれています。以下はカスタマイズされたエラーメッセージの一例です。

export const codeExample = `// Examples of customized error messages in the languageDictionary option
var options = {
  languageDictionary: {
    error: {
      login: {
        "lock.invalid_email_password": "Custom message about invalid credentials",
        "lock.network": "Custom message indicating a network error and suggesting the user check connection",
        "lock.unauthorized": "Custom message about a failure of permissions",
        "too_many_attempts": "Custom message indicating the user has failed to login too many times."
      },
      signUp: {
        "invalid_password": "Custom message indicating a password was invalid",
        "user_exists": "Custom message indicating that a user already exists"
      }
    }
  }
};

// Initiating our Auth0Lock
var lock = new Auth0Lock(
  '{yourClientId}',
  '{yourDomain}',
  options
);`;

<AuthCodeBlock children={codeExample} language="javascript" />

<div id="custom-errors-in-rules">
  ## ルールのカスタムエラー
</div>

[ルール](/docs/ja-JP/ja-jp/customize/rules)やカスタムデータベーススクリプトからのカスタムエラーコードを返している場合には、カスタムエラーを以下のように扱うことができます。

* アプリケーションのリダイレクトURLで、`error`と`error_mesage`のクエリ文字列パラメーターを読み出す
* ホストされているページへ、カスタムエラーメッセージと共にユーザーをリダイレクトで戻し、そのメッセージを[フラッシュメッセージ](/docs/ja-JP/ja-jp/libraries/lock/lock-api-reference)で表示する

<div id="learn-more">
  ## もっと詳しく
</div>

* [Web用のLock](/docs/ja-JP/ja-jp/libraries/lock)
