ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.94k stars 1.85k forks source link

Etherscan returns next (if dont pass apiKey). #4432

Open ray372922 opened 1 year ago

ray372922 commented 1 year ago

Etherscan returns next (if dont pass apiKey).

{"status":"1","message":"OK-Missing/Invalid API Key, rate limit of 1/5sec applied","result":[{"address"...

Code checks that message is strongly "OK".

if (result.status != 1 || result.message != "OK") {
        const error: any = new Error("invalid response");
        error.result = JSON.stringify(result);
        if ((result.result || "").toLowerCase().indexOf("rate limit") >= 0) {
            error.throttleRetry = true;
        }
        throw error;
    }

After it, i have exception with TypeError: (result.result || "").toLowerCase is not a function because result in my request is logs array, not string.

Originally posted by @timaiv in https://github.com/ethers-io/ethers.js/discussions/2983

ricmoo commented 1 year ago

What version are you using? Is it the same case as this in v6 or is there another case that needs to handle it as a regex (I should probably change that to a startsWith, since v6 uses modern ES features ;)).