I'm probably missing something obvious here.
I'm using HttpClient
which throws HttpRequestException
that contains StatusCode
in the Message string.
How can I access that StatusCode
?
Edit: More info, I wrote this question in rush.
I'm using HttpClient
to access another API within my WebApi project. Yes, I know why I'm calling EnsureSuccessStatusCode()
. I want to propagate some errors downstream such as 404 and 403.
All I wanted was to consistently transform HttpRequestException
into HttpResponseException
using custom ExceptionFilterAttribute
.
Unfortunately, HttpRequestException
does not carry any extra info I could use besides the message. I was hoping to uncover StatusCode
in raw (int or enum) form.
Looks like I can either:
- Use the message to switch the status code (bleh)
- Or create my version of EnsureSuccessStatusCode and throw exception that's actually usable.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…