How to check http response code?
See original GitHub issueI had write the following code and I just understand it has an error.
Problem is that result.Error.Code
is binance code. But how to check http code? I didn’t find it.
public static async Task<long> GetPingAsync(IBinanceClient httpClient) {
while (true) {
var result = await httpClient.PingAsync().ConfigureAwait( false );
if (result.TryGetData( out var data )) return data; // If success then return result. Else repeat request or throw exception.
}
}
private static bool TryGetData<T>(this CallResult<T> result, out T data) {
if (result.Success) {
data = result.Data;
return true;
}
if (result.IsError5xx()) {
data = default;
return false;
}
throw new Exception( result.Error.ToString() );
}
// Here is a bug !!!
private static bool IsError5xx<T>(this CallResult<T> result) {
// HTTP 5XX return codes are used for internal errors; the issue is on Binance's side. It is important to NOT treat this as a failure operation; the execution status is UNKNOWN and could have been a success.
return !result.Success && result.Error.Code >= 500 && result.Error.Code <= 599; // todo: fix
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to Check HTTP Status Code: Server Response ...
In the main window of the program, enter your website homepage URL and click on the 'Start' button. As soon as crawling is...
Read more >How can I tell what is the http status code returned by ...
Hit F12 to get developer tools and look at the network tab. Shows you all status codes, whether page was from cache etc....
Read more >Bulk HTTP Status Tool | Fast & Free
How to check your HTTP status with the HTTP status tool ; 1. Enter your URL (or list of URLs) ; 2. Click...
Read more >HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >Bulk URL HTTP Status Code, Header & Redirect Checker ...
Paste up to 100 URLs and check status codes and redirect chains in one batch. By default HTTP URLs will be checked when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, the error codes listed at https://github.com/JKorf/CryptoExchange.Net/blob/master/CryptoExchange.Net/Objects/Error.cs don’t map to http status codes. I’ve exposed the http status code for rest requests by changing the return type from
CallResult<T>
toWebCallResult<T>
which has an extra ResponseStatusCode field which contains the http status code. This is available in version 4.0.8 which should be on Nuget in a few minutes.You can use the http status codes, however the binance error codes are generally more specific as to what the problem is. ResponseStatusCode is null when the request was either never send or there was no response from the server.