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); }
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); }
// ----------------------------------------------------------- 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); }
/// <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); } }
public ActionResult ErrorViewWithCode( [FromServices] ILogger logger, SiteError error) { return(ErrorView(logger, error.ToLocalizedString())); }
public ActionResult AjaxError(SiteError error) { return(AjaxError(error.ToLocalizedString())); }
public ActionResult AjaxGridErrorResponse(SiteError error) { return(AjaxGridErrorResponse(null, error.ToLocalizedString())); }