Exemplo n.º 1
0
 public static HttpStatusCode GetHttpErrorResponseCode(LeadGenerationValidationException validationException)
 {
     if (validationException.ErrorCode == "AccessDenied")
     {
         return(HttpStatusCode.Unauthorized);
     }
     else
     {
         return(HttpStatusCode.BadRequest);
     }
 }
        private HttpResponseMessage GetResponseDataForUI(Exception ex, HttpRequestHeaders httpRequestHeader)
        {
            string errorContextJson;
            LeadGenerationErrors errorContext = null;
            HttpStatusCode       httpStatusCode;

            if (ex is LeadGenerationValidationException)
            {
                LeadGenerationValidationException LeadgenerationException = ex as LeadGenerationValidationException;
                errorContext = new LeadGenerationErrors
                {
                    ErrorCode    = LeadgenerationException.ErrorCode,
                    ErrorMessage = LeadgenerationException.Message
                };

                httpStatusCode = HttpErrorResponseHandler.GetHttpErrorResponseCode(LeadgenerationException);
            }
            else
            {
                errorContext = new LeadGenerationErrors
                {
                    ErrorCode    = "Unhandled Exception",
                    ErrorMessage = ex.Message
                };

                httpStatusCode = HttpStatusCode.InternalServerError;
            }

            if (httpRequestHeader.Contains("GetFullExceptionWithTrace") &&
                Convert.ToString(httpRequestHeader.GetValues("GetFullExceptionWithTrace").FirstOrDefault()).ToUpper() == "TRUE")
            {
                string fullException = GetFullExceptionWithTrace(ex);
                errorContext.ErrorMessage = errorContext.ErrorMessage + Environment.NewLine + "\"Trace\" : " + fullException;
            }

            errorContextJson = JsonConvert.SerializeObject(errorContext);

            var resp = new HttpResponseMessage(httpStatusCode)
            {
                Content = new StringContent(errorContextJson, Encoding.UTF8, "application/json")
            };

            return(resp);
        }