예제 #1
0
        protected async Task <string> PostAsync2(object obj, int methodid, string controller = "", string action = "")
        {
            HttpResponseMessage responseMessage = await _api.PostAsync(obj, methodid, controller, action);

            if ((responseMessage == null) || (responseMessage.Content == null))
            {
                _logger.LogError(methodid, "responseMessage == null");
                return(null);
            }
            string responsedata = responseMessage.Content.ReadAsStringAsync().Result;

            if (responseMessage.IsSuccessStatusCode)
            {
                return(responsedata);
            }

            SiteError error = JsonConvert.DeserializeObject <SiteError>(responsedata);

            if (error == null)
            {
                _logger.LogError(methodid, "error == null");
                return(null);
            }
            _logger.LogError(methodid, string.Format("{0}; {1}", error.Code, error.Message));
            return(null);
        }
예제 #2
0
        public void LogErrorGettingSiteResponse(Site site, Exception ex)
        {
            _siteErrorRepository.DeleteOld(site);

            //TODO: pegar o ultimo erro nas 24 horas passadas, caso exista atualizar um contador de erros ++
            SiteError siteError = new SiteError();

            siteError.Site         = site;
            siteError.Date         = DateTime.Now;
            siteError.ErrorDetails = ex.Message;
            if (ex is RequestException)
            {
                _logger.LogInfo("Request exception - Error getting site's contents - " + site.SiteName);
                siteError.ErrorType = ErrorTypes.RequestError.ToString();
                _logger.LogError(ex);
            }
            else if (ex is SpecificElementException)
            {
                _logger.LogInfo("Error getting specific element from site's contents -" + site.SiteName);
                siteError.ErrorType = ErrorTypes.SpecificElementError.ToString();
                _logger.LogError(ex);
            }
            else
            {
                _logger.LogInfo("Generic error getting site's contents -" + site.SiteName);
                siteError.ErrorType = ErrorTypes.GenericError.ToString();
                _logger.LogError(ex);
            }

            site.SiteErrors.Add(siteError);
            _siteErrorRepository.Save(siteError);
            _siteRepository.SaveOrUpdate(site);
        }
예제 #3
0
        // -----------------------------------------------------------

        protected async Task <string> PostAsync2(object obj, int methodid, string controller = "", string action = "")
        {
            Assert.NotNull(_api);

            HttpResponseMessage responseMessage = await _api.PostAsync(obj, methodid, controller, action);

            Assert.False((responseMessage == null) || (responseMessage.Content == null));

            string responsedata = responseMessage.Content.ReadAsStringAsync().Result;

            Assert.True(responseMessage.IsSuccessStatusCode);
            if (responseMessage.IsSuccessStatusCode)
            {
                return(responsedata);
            }

            SiteError error = JsonConvert.DeserializeObject <SiteError>(responsedata);

            Assert.IsNotNull(error);
            return(null);
        }
예제 #4
0
        /// <summary>
        /// Localized string with error description.
        /// </summary>
        public static string ToLocalizedString(this SiteError siteError)
        {
            switch (siteError)
            {
            case SiteError.ParameterMissing:
                return(LNG.SiteError_ParameterMissing);

            case SiteError.InvalidParameter:
                return(LNG.SiteError_InvalidParameter);

            case SiteError.ObjectMissing:
                return(LNG.SiteError_ObjectMissing);

            case SiteError.Unauthorized:
                return(LNG.SiteError_Unauthorized);

            case SiteError.AccessDenied:
                return(LNG.SiteError_AccessDenied);

            default:
                return(LNG.SiteError_UnknownError);
            }
        }
예제 #5
0
 public ActionResult ErrorViewWithCode(
     [FromServices] ILogger logger,
     SiteError error)
 {
     return(ErrorView(logger, error.ToLocalizedString()));
 }
예제 #6
0
 public ActionResult AjaxError(SiteError error)
 {
     return(AjaxError(error.ToLocalizedString()));
 }
예제 #7
0
 public ActionResult AjaxGridErrorResponse(SiteError error)
 {
     return(AjaxGridErrorResponse(null, error.ToLocalizedString()));
 }