Exemple #1
0
        /// <summary>
        /// If there is error, converts its details to JSONDataMap
        /// </summary>
        public static Azos.Serialization.JSON.JsonDataMap ToJSONDataMap(this Exception error, bool recurse = true, bool stackTrace = false)
        {
            if (error == null)
            {
                return(null);
            }
            var result = new Azos.Serialization.JSON.JsonDataMap(false);

            result["Type"] = error.GetType().FullName;
            result["Msg"]  = error.Message;
            result["Data"] = error.Data;
            result["Src"]  = error.Source;
            if (stackTrace)
            {
                result["STrace"] = error.StackTrace;
            }

            if (recurse)
            {
                result["Inner"] = error.InnerException.ToJSONDataMap(recurse);
            }
            else
            {
                result["Inner.Type"] = error.InnerException != null?error.InnerException.GetType().FullName : null;

                result["Inner.Msg"] = error.InnerException != null ? error.InnerException.Message : null;
                if (stackTrace)
                {
                    result["Inner.STrace"] = error.InnerException != null ? error.InnerException.StackTrace : null;
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Describes exception for client response transmission as JSONDataMap
        /// </summary>
        public static Serialization.JSON.JsonDataMap ToClientResponseJSONMap(this Exception error, bool detailed)
        {
            var actual = error;

            if (actual is FilterPipelineException fpe)
            {
                actual = fpe.RootException;
            }

            var result = new Azos.Serialization.JSON.JsonDataMap();

            result["OK"] = false;

            if (actual is IHttpStatusProvider st)
            {
                result["HttpStatusCode"]        = st.HttpStatusCode;
                result["HttpStatusDescription"] = st.HttpStatusDescription;
            }

            if (detailed)
            {
                result["Error"]      = error.Message;
                result["Type"]       = error.GetType().FullName;
                result["StackTrace"] = error.StackTrace;
                if (error.InnerException != null)
                {
                    result["Inner"] = error.InnerException.ToClientResponseJSONMap(detailed);
                }
            }
            else
            {
                result["Error"] = actual.GetType().Name;
            }

            result["IsAuthorization"] = Security.AuthorizationException.IsDenotedBy(actual);

            return(result);
        }