Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error when rpc url fails. #1238

Open
ikemHood opened this issue Oct 3, 2024 · 0 comments
Open

Add Error when rpc url fails. #1238

ikemHood opened this issue Oct 3, 2024 · 0 comments
Assignees
Labels
Type: bug Something isn't working

Comments

@ikemHood
Copy link

ikemHood commented Oct 3, 2024

Is your feature request related to a problem? Please describe.

I've been using alchemy rpc for a while and it works fine wothout appending an apikeys sometimes.

maybe a change from them or something but it suddenly didn't work anymore with 404 error..

making contract calls now fails with

2415 |    * @param response string[] - response from the method
2416 |    * @return Result - parsed response corresponding to the abi
2417 |    */
2418 |   parse(method, response) {
2419 |     const { outputs } = this.abi.find((abi) => abi.name === method);
2420 |     const responseIterator = response.flat()[Symbol.iterator]();
                                    ^
TypeError: undefined is not an object (evaluating 'response.flat')
      at parse (/home/ikem/dev/horuslab/karst-backend/node_modules/starknet/dist/index.mjs:2420:30)

Throwing a better error when the apicall fails make it easier to debug and find the actual cause of a misbehaior

A little digging and await rawResult.json(); here returns error as undefind when this error happens

  async fetchEndpoint(method, params) {
    try {
      const rawResult = await this.fetch(method, params, this.requestId += 1);
      const { error, result } = await rawResult.json();
      console.log({error, result})
      this.errorHandler(method, params, error);
      return result;
    } catch (error) {
      this.errorHandler(method, params, error?.response?.data, error);
      throw error;
    }
  }

{ error: undefined, result: undefined, }

Describe the solution you'd like
Throw a detail rpc error when the api call fails

  async fetchEndpoint(method, params) {
    try {
      const rawResult = await this.fetch(method, params, this.requestId += 1);
      const { error, result } = await rawResult.json();
      if(!error && !result){
        throw this.errorHandler(method, params, error);
      }
      this.errorHandler(method, params, error);
      return result;
    } catch (error) {
      this.errorHandler(method, params, error?.response?.data, error);
      throw error;
    }
  }
@ikemHood ikemHood added the Type: feature New feature or request label Oct 3, 2024
@penovicp penovicp added Type: bug Something isn't working and removed Type: feature New feature or request labels Oct 3, 2024
@penovicp penovicp self-assigned this Oct 4, 2024
@starknet-io starknet-io deleted a comment Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants