Method which handle HttpResposeMessage 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);
        }
    }
}
Considering that there is no else to if (!response.IsSuccessStatusCode), you should do:

if (response.IsSuccessStatusCode)
{
   return;
}


This saves on indentation and makes your method easier to read.



I'd use string.Format for things like this:

message = this.localizer["Forbidden"] + ": " + this.localizer["You have not the appropriate rights to access this page."];




Why is localizer a property on the class this method belongs to, but logger is not? And why do you need to write this.localizer?



In the end there's not much code to review, and perhaps you should consider posting the whole class.