<commit_before>﻿namespace TodoTemplate.App.Shared
{
    public partial class MainLayout : IAsyncDisposable
    {
        public bool IsUserAuthenticated { get; set; }
        public bool IsMenuOpen { get; set; } = false;

        [Inject]
        public IStateService StateService { get; set; } = default!;

        [Inject]
        public IExceptionHandler ExceptionHandler { get; set; } = default!;

        [Inject]
        public TodoTemplateAuthenticationStateProvider TodoTemplateAuthenticationStateProvider { get; set; } = default!;

        protected override async Task OnInitializedAsync()
        {
            TodoTemplateAuthenticationStateProvider.AuthenticationStateChanged += VerifyUserIsAuthenticatedOrNot;

            IsUserAuthenticated = await StateService.GetValue(nameof(IsUserAuthenticated), async () => await TodoTemplateAuthenticationStateProvider.IsUserAuthenticated());

            await base.OnInitializedAsync();
        }

        async void VerifyUserIsAuthenticatedOrNot(Task<AuthenticationState> task)
        {
            try
            {
                IsUserAuthenticated = await TodoTemplateAuthenticationStateProvider.IsUserAuthenticated();
            }
            catch (Exception ex)
            {
                ExceptionHandler.OnExceptionReceived(ex);
            }
            finally
            {
                StateHasChanged();
            }
        }

        private void ToggleMenuHandler()
        {
            IsMenuOpen = !IsMenuOpen;
        }

        public async ValueTask DisposeAsync()
        {
            TodoTemplateAuthenticationStateProvider.AuthenticationStateChanged -= VerifyUserIsAuthenticatedOrNot;
        }
    }<commit_msg>fix exception handling issue in the main layout #1653 (#1663)<commit_after>﻿namespace TodoTemplate.App.Shared
{
    public partial class MainLayout : IAsyncDisposable
    {
        public bool IsUserAuthenticated { get; set; }
        public bool IsMenuOpen { get; set; } = false;

        [Inject]
        public IStateService StateService { get; set; } = default!;

        [Inject]
        public IExceptionHandler ExceptionHandler { get; set; } = default!;

        [Inject]
        public TodoTemplateAuthenticationStateProvider TodoTemplateAuthenticationStateProvider { get; set; } = default!;

        protected override async Task OnInitializedAsync()
        {
            try
            {
                TodoTemplateAuthenticationStateProvider.AuthenticationStateChanged += VerifyUserIsAuthenticatedOrNot;

                IsUserAuthenticated = await StateService.GetValue(nameof(IsUserAuthenticated), async () => await TodoTemplateAuthenticationStateProvider.IsUserAuthenticated());

                await base.OnInitializedAsync();
            }
            catch (Exception exp)
            {
                ExceptionHandler.OnExceptionReceived(exp);
            }
        }

        async void VerifyUserIsAuthenticatedOrNot(Task<AuthenticationState> task)
        {
            try
            {
                IsUserAuthenticated = await TodoTemplateAuthenticationStateProvider.IsUserAuthenticated();
            }
            catch (Exception ex)
            {
                ExceptionHandler.OnExceptionReceived(ex);
            }
            finally
            {
                StateHasChanged();
            }
        }

        private void ToggleMenuHandler()
        {
            IsMenuOpen = !IsMenuOpen;
        }

        public async ValueTask DisposeAsync()
        {
            TodoTemplateAuthenticationStateProvider.AuthenticationStateChanged -= VerifyUserIsAuthenticatedOrNot;
        }
    }
{'fraction_non_alphanumeric': 0.06701455644053832, 'fraction_numerical': 0.0021971985718209283, 'mean_word_length': 2.118150684931507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6205461', 'n_tokens_mistral': 867, 'n_tokens_neox': 849, 'n_words': 172}