示例#1
0
        private static void ProvideAmfFault(ref Exception error, MessageVersion version, ref Message msg, OperationContext oc)
        {
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            // TRICK: get original stack trace here
            string stackTrace = IsDev ? error.StackTrace : string.Empty;

            if (!(error is FaultException <Error>))
            {
                string details = (IsDev || error is IUserMessageException)
                    ? error.Message
                    : ErrorsTexts.UnexpectedError;
                var error2 =
                    new FaultException <Error>(
                        new Error(
                            Errors.CODE_ERRORTYPE_GENERIC_ERROR,
                            ErrorsTexts.UnexpectedError_Subject,
                            details),
                        details);
                error = error2;
            }

            AmfErrorHandler.ProvideFaultExternally(oc, true, stackTrace, error, version, ref msg);
        }
示例#2
0
        /// <summary>
        /// The provide fault.
        /// </summary>
        /// <param name="error">
        /// The error.
        /// </param>
        /// <param name="version">
        /// The version.
        /// </param>
        /// <param name="msg">
        /// The message.
        /// </param>
        public void ProvideFault(Exception error, MessageVersion version, ref Message msg)
        {
            OperationContext oc = OperationContext.Current;


            Exception originalException = error;

            if (oc != null)
            {
                string wasCalledOn = oc.EndpointDispatcher.EndpointAddress.Uri.ToString();
                if (wasCalledOn.EndsWith("jsonp", StringComparison.InvariantCultureIgnoreCase))
                {
                    var resultedError = new WcfErrorWrapper
                    {
                        ErrorCode     = Errors.CODE_ERRORTYPE_GENERIC_ERROR,
                        Message       = error.Message,
                        StackTrace    = error.StackTrace,
                        FullException = error.ToString()
                    };
                    OutgoingWebResponseContext response = WebOperationContext.Current.With(x => x.OutgoingResponse);
                    response.StatusCode  = HttpStatusCode.OK;
                    response.ContentType = "application/json";

                    if (error is FaultException <Error> )
                    {
                        var webError = (FaultException <Error>)error;
                        resultedError.ErrorCode = webError.Detail.Return(x => x.errorCode, resultedError.ErrorCode);
                        resultedError.Message   = webError.Detail.Return(x => x.errorMessage, resultedError.Message);
                        resultedError.Title     = "Application Error";
                    }
                    else
                    {
                        resultedError.Message = this.IsDev ? error.ToString() : ErrorsTexts.UnexpectedError;
                        resultedError.Title   = ErrorsTexts.UnexpectedError_Subject;
                    }

                    msg = Message.CreateMessage(
                        version,
                        "json",
                        resultedError,
                        new DataContractJsonSerializer(typeof(WcfErrorWrapper)));
                    var jsonResult = new WebBodyFormatMessageProperty(WebContentFormat.Json);
                    msg.Properties.Add(WebBodyFormatMessageProperty.Name, jsonResult);
                }
                else if (wasCalledOn.EndsWith("amf", StringComparison.InvariantCultureIgnoreCase) ||
                         wasCalledOn.EndsWith("amfssl", StringComparison.InvariantCultureIgnoreCase))
                {
                    string stackTrace = this.IsDev ? error.StackTrace : string.Empty;
                    if (!(error is FaultException <Error>))
                    {
                        string details = this.IsDev ? error.ToString() : ErrorsTexts.UnexpectedError;
                        var    error2  =
                            new FaultException <Error>(
                                new Error(
                                    Errors.CODE_ERRORTYPE_GENERIC_ERROR,
                                    ErrorsTexts.UnexpectedError_Subject,
                                    details),
                                details);
                        error = error2;
                    }

                    AmfErrorHandler.ProvideFaultExternally(oc, true, stackTrace, error, version, ref msg);
                }
            }

            this.logger.Error("Unhandled WCF exception", originalException);
        }