Esempio n. 1
0
        public void ProvideFault(Exception error, HttpResponse httpResponse)
        {
            OWAFaultHandler.LogException(error);
            if (!httpResponse.IsClientConnected)
            {
                return;
            }
            httpResponse.TrySkipIisCustomErrors = true;
            httpResponse.StatusCode             = 500;
            httpResponse.StatusDescription      = Strings.GetLocalizedString(-1269063878);
            httpResponse.ContentType            = "application/json; charset=utf-8";
            if (error is OwaExtendedErrorCodeException)
            {
                OwaExtendedErrorCodeException ex = (OwaExtendedErrorCodeException)error;
                OwaExtendedError.SendError(httpResponse.Headers, delegate(HttpStatusCode sc)
                {
                    httpResponse.StatusCode = (int)sc;
                }, ex.ExtendedErrorCode, ex.Message, ex.User, ex.ErrorData);
            }
            else
            {
                MissingIdentityException ex2 = error as MissingIdentityException;
                if (ex2 != null)
                {
                    httpResponse.StatusCode        = (int)ex2.StatusCode;
                    httpResponse.StatusDescription = ex2.StatusDescription;
                    httpResponse.Headers[WellKnownHeader.MSDiagnostics]  = (ex2.DiagnosticText ?? string.Empty);
                    httpResponse.Headers[WellKnownHeader.Authentication] = (ex2.ChallengeString ?? string.Empty);
                }
            }
            JsonFaultResponse          jsonFaultResponse          = JsonFaultResponse.CreateFromException(error);
            DataContractJsonSerializer dataContractJsonSerializer = OWAFaultHandler.CreateJsonSerializer(jsonFaultResponse.GetType());

            dataContractJsonSerializer.WriteObject(httpResponse.OutputStream, jsonFaultResponse);
        }
        // Token: 0x06001194 RID: 4500 RVA: 0x000436C4 File Offset: 0x000418C4
        public static JsonFaultResponse CreateFromException(Exception exception)
        {
            JsonFaultResponse jsonFaultResponse = new JsonFaultResponse();

            jsonFaultResponse.Body.ErrorCode = 500;
            if (!Globals.IsAnonymousCalendarApp && Global.WriteStackTraceOnISE)
            {
                jsonFaultResponse.Body.StackTrace = exception.ToString();
            }
            exception = JsonFaultResponse.UnwrapUnderlyingException(exception);
            jsonFaultResponse.Body.ExceptionName = exception.GetType().Name;
            OwaServiceFaultException ex = exception as OwaServiceFaultException;

            if (ex != null)
            {
                ServiceError serviceError = ex.ServiceError;
                jsonFaultResponse.Body.ResponseCode = serviceError.MessageKey.ToString();
                jsonFaultResponse.Body.FaultMessage = serviceError.MessageText;
                jsonFaultResponse.Body.IsTransient  = OWAFaultHandler.IsTransientError(ex.ServiceException);
                OWAFaultHandler.SetBackOffPeriodInMs(ex.ServiceException, jsonFaultResponse.Body);
                return(jsonFaultResponse);
            }
            MissingIdentityException ex2 = exception as MissingIdentityException;

            if (ex2 != null)
            {
                jsonFaultResponse.Body.ErrorCode    = (int)ex2.StatusCode;
                jsonFaultResponse.Body.ResponseCode = ex2.StatusCode.ToString();
                jsonFaultResponse.Body.FaultMessage = ex2.StatusDescription;
                jsonFaultResponse.Body.IsTransient  = false;
                OWAFaultHandler.SetBackOffPeriodInMs(exception, jsonFaultResponse.Body);
                return(jsonFaultResponse);
            }
            jsonFaultResponse.Body.FaultMessage = exception.Message;
            jsonFaultResponse.Body.IsTransient  = OWAFaultHandler.IsTransientError(exception);
            OWAFaultHandler.SetBackOffPeriodInMs(exception, jsonFaultResponse.Body);
            return(jsonFaultResponse);
        }
Esempio n. 3
0
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            OWAFaultHandler.LogException(error);
            WebBodyFormatMessageProperty property            = new WebBodyFormatMessageProperty(WebContentFormat.Json);
            HttpResponseMessageProperty  responseMessageProp = new HttpResponseMessageProperty
            {
                StatusCode        = HttpStatusCode.InternalServerError,
                StatusDescription = Strings.GetLocalizedString(-1269063878)
            };

            responseMessageProp.Headers.Set("Content-Type", "application/json; charset=utf-8");
            if (error is OwaExtendedErrorCodeException)
            {
                OwaExtendedErrorCodeException ex = (OwaExtendedErrorCodeException)error;
                OwaExtendedError.SendError(responseMessageProp.Headers, delegate(HttpStatusCode sc)
                {
                    responseMessageProp.StatusCode = sc;
                }, ex.ExtendedErrorCode, ex.Message, ex.User, ex.ErrorData);
            }
            else
            {
                MissingIdentityException ex2 = error as MissingIdentityException;
                if (ex2 != null)
                {
                    responseMessageProp.StatusCode        = ex2.StatusCode;
                    responseMessageProp.StatusDescription = ex2.StatusDescription;
                    responseMessageProp.Headers.Set(WellKnownHeader.MSDiagnostics, ex2.DiagnosticText ?? string.Empty);
                    responseMessageProp.Headers.Set(WellKnownHeader.Authentication, ex2.ChallengeString ?? string.Empty);
                }
            }
            JsonFaultResponse jsonFaultResponse = JsonFaultResponse.CreateFromException(error);

            fault = Message.CreateMessage(version, string.Empty, jsonFaultResponse, new DataContractJsonSerializer(jsonFaultResponse.GetType()));
            fault.Properties.Add("WebBodyFormatMessageProperty", property);
            fault.Properties.Add(HttpResponseMessageProperty.Name, responseMessageProp);
        }