question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to check http response code?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JKorfcommented, Feb 27, 2019

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> to WebCallResult<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.

0reactions
JKorfcommented, Mar 7, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found