Example #1
0
        private StructuredErrors ConvertToNestedErrors(Exception exception)
        {
            StructuredErrors structuredErrors = null;

            while (exception != null)
            {
                StructuredError    structuredError = new StructuredError();
                LocalizedException ex = exception as LocalizedException;
                if (ex != null)
                {
                    structuredError.Code = ex.ErrorCode;
                    structuredError.Info = ex.LocalizedString;
                }
                else
                {
                    structuredError.Code = 0;
                    structuredError.Info = exception.ToString();
                }
                Type type = exception.GetType();
                structuredError.Name       = type.FullName;
                structuredError.Guid       = type.GUID.ToString("n");
                structuredError.Message    = exception.Message;
                structuredError.Source     = exception.Source;
                structuredError.TargetSite = exception.TargetSite.Name;
                if (structuredErrors == null)
                {
                    structuredErrors = new StructuredErrors();
                }
                structuredErrors.AddError(structuredError);
                exception = exception.InnerException;
            }
            return(structuredErrors);
        }
Example #2
0
        private void SerializeRestException(App app, HttpContext context, StringBuilder builder, StringWriter writer, RestServiceException exception)
        {
            if (Format.ToLower() == "json")
            {
                if (app.RestServiceResponseMode == RestServiceResponseMode.Simple)
                {
                    context.Response.Write(JsonConvert.SerializeObject(exception));
                }
                else
                {
                    StructuredError err = new StructuredError
                    {
                        Error = exception
                    };

                    context.Response.Write(JsonConvert.SerializeObject(err));
                }
            }
            else
            {
                System.Xml.Serialization.XmlSerializer x = null;

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent      = true;
                settings.CloseOutput = true;

                if (app.RestServiceResponseMode == RestServiceResponseMode.Simple)
                {
                    x = new System.Xml.Serialization.XmlSerializer(exception.GetType());

                    using (XmlWriter xmlwriter = XmlWriter.Create(builder, settings))
                    {
                        x.Serialize(xmlwriter, exception);
                        writer.Close();
                    }
                }
                else
                {
                    StructuredError err = new StructuredError
                    {
                        Error = exception
                    };
                    x = new System.Xml.Serialization.XmlSerializer(err.GetType());

                    using (XmlWriter xmlwriter = XmlWriter.Create(builder, settings))
                    {
                        x.Serialize(xmlwriter, err);
                        writer.Close();
                    }
                }


                context.Response.Write(builder.ToString());
            }
        }