<commit_before>﻿using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace Typeset.Web
{
    public class ExceptionHandlingConfig
    {
        public static void RegisterEvents(HttpApplication context)
        {
            context.Error += new EventHandler(context_Error);
            TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            GlobalConfiguration.Configuration.MessageHandlers.Add(new WebApiMessageHandler());
        }

        private static void context_Error(object sender, EventArgs e)
        {
            if (sender is HttpApplication)
            {
                var context = sender as HttpApplication;
                var exception = context.Server.GetLastError().GetBaseException();
                context.Server.ClearError();
            }
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exception = e.ExceptionObject as Exception;

            if (e.IsTerminating)
            {
            }
            else
            {
            }
        }

        private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            e.SetObserved();
        }

        public class WebApiMessageHandler : DelegatingHandler
        {
            protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                return base.SendAsync(request, cancellationToken)
                    .ContinueWith(r =>
                    {
                        // inspect result for status code and handle accordingly
                        return r.Result;
                    });
            }
        }
    }

    
}<commit_msg>Code Cleanup<commit_after>﻿using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;

namespace Typeset.Web
{
    public class ExceptionHandlingConfig
    {
        public static void RegisterEvents(HttpApplication context)
        {
            context.Error += new EventHandler(context_Error);
            TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            GlobalConfiguration.Configuration.MessageHandlers.Add(new WebApiMessageHandler());
        }

        private static void context_Error(object sender, EventArgs e)
        {
            if (sender is HttpApplication)
            {
                var context = sender as HttpApplication;
                var exception = context.Server.GetLastError().GetBaseException();
                context.Server.ClearError();
            }
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exception = e.ExceptionObject as Exception;

            if (e.IsTerminating)
            {
            }
            else
            {
            }
        }

        private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            e.SetObserved();
        }

        private class WebApiMessageHandler : DelegatingHandler
        {
            protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                return base.SendAsync(request, cancellationToken)
                    .ContinueWith(r =>
                    {
                        // inspect result for status code and handle accordingly
                        return r.Result;
                    });
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06292026897214217, 'fraction_numerical': 0.0, 'mean_word_length': 2.009393063583815, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7582098', 'n_tokens_mistral': 950, 'n_tokens_neox': 917, 'n_words': 203}