예제 #1
0
        private byte[] GetServiceSideErrorBody(Exception ex, bool request)
        {
            if (request)
            {
                //this can happen only with default handler on service side
                //typically when lacking access to file system
                SoapLoggerService.SetRequestException(ex);

                //in order to force HTTP 500 Internal Server Error and avoid processing
                //we overwrite request with deliberately invalid body
                return(ErrorBody.InvalidRequest());
            }

            // response
            string message = null;

            if (ex is LoggerException)
            {
                message = ex.Message;
            }
            else
            {
                message = ex.ToString();
            }

            string soapFault = ErrorBody.CreateSoapFaultResponse(message);

            byte[] errorBody = Encoding.UTF8.GetBytes(soapFault);
            return(errorBody);
        }
예제 #2
0
        protected override byte[] GetRequestErrorBody(Exception ex)
        {
            //this can happen only with default handler
            //typically when lacking access to file system
            SoapLoggerService.SetRequestException(ex);

            //in order to force HTTP 500 Internal Server Error and avoid processing
            //we overwrite request with deliberately invalid body
            return(ErrorBody.GetSoapInvalidRequest());
        }
예제 #3
0
        private void HandleCreationException(ApiCreateException <OrganizationalHierarchyResource> apiException)
        {
            ErrorBody error = apiException.ErrorBody;

            if (error.ErrorCode.Equals(AlreadyExistsErrorCode))
            {
                Console.WriteLine(apiException.PostedContent.Name + " already exists!");
            }
            else
            {
                throw apiException;
            }
        }
예제 #4
0
        protected override bool TryParseErrorBody(string content, out ErrorBody error)
        {
            var errorResponse = Deserialize <ErrorResponse>(content);

            if (errorResponse == null)
            {
                error = null;
                return(false);
            }

            error = new ErrorBody
            {
                Message = errorResponse.Message
            };

            return(true);
        }
예제 #5
0
        protected override byte[] GetResponseErrorBody(Exception ex)
        {
            string message = null;

            if (ex is LoggerException)
            {
                message = ex.Message;
            }
            else
            {
                message = ex.ToString();
            }

            string soapFault = ErrorBody.GetSoapFaultResponse(message);

            byte[] errorBody = Encoding.UTF8.GetBytes(soapFault);
            return(errorBody);
        }
예제 #6
0
        /**
         * 对请求的信息转换为ErrorBody
         */
        public static async Task <ErrorBody> ExtractError(HttpResponseMessage response)
        {
            if (response.IsSuccessStatusCode)
            {
                throw new InvalidOperationException("请求成功,无错误信息");
            }
            var str = await response.Content.ReadAsStringAsync();

            ErrorBody?body = null;

            try
            {
                body = JsonConvert.DeserializeObject <ErrorBody>(str);
            }
            catch (Exception e)
            {
                body = new ErrorBody()
                {
                    Code = (int)response.StatusCode,
                    Msg  = (int)response.StatusCode >= 500 ?"服务器异常":"错误请求"
                };
            }
            return(body);
        }
 public void Init()
 {
     instance = new ErrorBody();
 }
예제 #8
0
 protected virtual bool TryParseErrorBody(string content, out ErrorBody error)
 {
     error = null;
     return(false);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="errorBody"></param>
 /// <returns></returns>
 internal static SFExpressException ThrowException(ErrorBody errorBody)
 {
     return(new SFExpressException(errorBody.Code, errorBody.Message));
 }
예제 #10
0
 public ApiException(ErrorBody body) : base(body.Msg)
 {
     this.Code  = body.Code;
     this.Value = body.Data;
 }
 internal ErrorResponse(ErrorBody error)
 {
     Error = error;
 }