I need to create method which handle HttpResposeMessage. Method should throw an exception if error exist, client will handle rest. You can see my code bellow. This code is working fine and doing what I want, but still it looks quite ugly to me.
Do you have some ideas for nicer implementation?
  [Authorize]
  public abstract class BaseController : Controller
    {
        protected readonly ILogger logger;
        protected readonly IHostingEnvironment env;
        private readonly IStringLocalizer localizer;
        public BaseController(ILogger logger, IHostingEnvironment env, IStringLocalizer localizer)
        {
            this.logger = logger;
            this.env = env;
            this.localizer = localizer;
        }
       protected void HandleResponseError(HttpResponseMessage response, ILogger logger)
        {
        if (!response.IsSuccessStatusCode)
        {
            var message = String.Empty;
            if (response.StatusCode.Equals(HttpStatusCode.Forbidden))
            {
                message = this.localizer["Forbidden"] + ": " + this.localizer["You have not the appropriate rights to access this page."];
            }
            else
            {
                try
                {
                    message = response.Content.ReadAsStringAsync().Result;
                    if (string.IsNullOrWhiteSpace(message))
                    {
                        message = message = this.localizer["Communication error with server"];
                    }
                }
                catch
                {
                    message = this.localizer["Communication error with server"];
                }
            }
            logger.LogError($"Client error message {message} !");
            throw new ApplicationException(message);
        }
    }
}
    
localizeris a field but theloggernot. You should post the entire code. There seem to be much more wrong with it. \$\endgroup\$