<commit_before>﻿// Plato.NET
// Copyright (c) 2016 ReflectSoftware Inc.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 

using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Plato.Messaging.Enums;
using Plato.Messaging.Exceptions;
using System;

namespace Plato.Messaging.Implementations.AMQ
{
    /// <summary>
    /// 
    /// </summary>
    internal static class AMQExceptionHandler
    {
        /// <summary>
        /// Exceptions the handler.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="ex">The ex.</param>
        /// <returns></returns>
        public static Exception ExceptionHandler(IConnection connection, Exception ex)
        {
            if (ex is NullReferenceException)
            {
                if (connection == null)
                {
                    return new MessageException(MessageExceptionCode.LostConnection, ex.Message, ex);
                }
            }

            if (ex is System.IO.IOException 
            || ex is NMSConnectionException
            || ex is ConnectionClosedException
            || ex is BrokerException
            || ex is IOException
            || ex is InvalidClientIDException
            || ex is NMSException)
            {
                return new MessageException(MessageExceptionCode.LostConnection, ex.Message, ex);
            }

            return null;
        }
    }
}<commit_msg>Provided a more detail ExceptionHandler message.<commit_after>﻿// Plato.NET
// Copyright (c) 2016 ReflectSoftware Inc.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 

using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Plato.Messaging.Enums;
using Plato.Messaging.Exceptions;
using System;

namespace Plato.Messaging.Implementations.AMQ
{
    /// <summary>
    /// 
    /// </summary>
    internal static class AMQExceptionHandler
    {
        /// <summary>
        /// Exceptions the handler.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="ex">The ex.</param>
        /// <returns></returns>
        public static Exception ExceptionHandler(IConnection connection, Exception ex)
        {
            var eMsg = $"Unable to connect or the connection to the ActiveMQ Broker is no longer available for the following reason: '{ex.Message}'";

            if (ex is NullReferenceException)
            {
                if (connection == null)
                {
                    return new MessageException(MessageExceptionCode.LostConnection, eMsg, ex);
                }
            }

            if (ex is System.IO.IOException 
            || ex is NMSConnectionException
            || ex is ConnectionClosedException
            || ex is BrokerException
            || ex is IOException
            || ex is InvalidClientIDException
            || ex is NMSException)
            {
                return new MessageException(MessageExceptionCode.LostConnection, eMsg, ex);
            }

            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.09626345788473717, 'fraction_numerical': 0.0037998733375554147, 'mean_word_length': 1.8382749326145553, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '7588823', 'n_tokens_mistral': 811, 'n_tokens_neox': 755, 'n_words': 228}