C
C#2y ago
İrşat

HttpRequestException Error Handling

It says the target actively refused it. It's because I didn't launch my API. Therefore it cannot request something and gives me this error. If we put try catch aside for a minute, is there a nice way to just skip these codes if it refuses? I will send empty lists to the client and just say "Sorry, we are having some technical issues." or something.
6 Replies
İrşat
İrşat2y ago
It was not giving me any error while using HttpClient _httpClient. It started after using IHttpClientFactory httpClientFactory
Yawnder
Yawnder2y ago
If it's an API, you need to respond with appropriate error codes for sure.
İrşat
İrşat2y ago
yeah, but it doesn't go into api in the first place. Try catch can easily do that but i am trying to learn alternatives string raw = await _httpClient.GetStringAsync("posts"); For example. (still up to date)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
İrşat
İrşat2y ago
I was just asking for a method and concept. There is no issue at all. As I said, I don't launch the web api, it's a choice. That's why it gives me error. I am asking this to be able to give something to the client even if no data comes
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View