Controller calls web api, how to handle http error codes returned from API
I think you can log the time, url, status code, response content and other info can help you. A Example From My Project
private static async Task<T> HandleHttpResponse<T>(HttpResponseMessage response)
{
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
return JsonHelper.ToObject<T>(HandleHttpResult(result));
}
else
{
var result = await response.Content.ReadAsStringAsync();
LogHelper.WriteLog($"请求{response.RequestMessage.RequestUri}错误,错误描述:{response.StatusCode},错误码:{response.StatusCode.ToInt32()},错误内容:{result}", $"{nameof(RemoteServerHelper)}_{nameof(HandleHttpResponse)}", true);
}
return default;
}