2

I need to remove EnsureSuccessStatusCode() method from my code and throw HttpRequestException manually. Looking at internals of EnsureSuccessStatusCode:

public HttpResponseMessage EnsureSuccessStatusCode()
    {
      if (!this.IsSuccessStatusCode)
      {
        if (this.content != null)
          this.content.Dispose();
        throw new HttpRequestException(string.Format((IFormatProvider) CultureInfo.InvariantCulture, SR.net_http_message_not_success_statuscode, new object[2]
        {
          (object) this.statusCode,
          (object) this.ReasonPhrase
        }));
      }
      return this;
    }

How can I replace 'SR.net_http_message_not_success_statuscode' in this case? As it is an internal property and I cannot use it in my code. I want something like this:

throw new HttpRequestException(string.Format(CultureInfo.InvariantCulture, "StatusCode: {0}, ReasonPhrase: {1}", new object[]
                        {
                            response.StatusCode,
                            response.ReasonPhrase
                        }));

Is it correct replacement?

SimonD
  • 1,441
  • 2
  • 18
  • 30

0 Answers0