Code Monkey home page Code Monkey logo

Comments (7)

NoahZinsmeister avatar NoahZinsmeister commented on May 19, 2024 1

hey @pcowgill, thanks for the report!

makes sense, i override that error locally with this snippet: https://github.com/NoahZinsmeister/web3-react/blob/latest/src/declarations.ts#L20. looking at MDN though, it seems like name might be the right property for what i'm trying to accomplish: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name.

i'm going to keep the issue open and experiment with this in the next version.

from web3-react.

NoahZinsmeister avatar NoahZinsmeister commented on May 19, 2024 1

🙏 that sounds perfect, i'll try that!

from web3-react.

NoahZinsmeister avatar NoahZinsmeister commented on May 19, 2024 1

going to close this, as v6 uses custom errors which can be checked with instanceof! thanks for bringing this up.

from web3-react.

pcowgill avatar pcowgill commented on May 19, 2024

@NoahZinsmeister Thanks for the example of how to override it! Agreed, I think name would suit your needs here.

from web3-react.

pcowgill avatar pcowgill commented on May 19, 2024

Also, you can subclass errors so that they’ll have name set automatically in the case of a frequently used “error code”

from web3-react.

pcowgill avatar pcowgill commented on May 19, 2024

@NoahZinsmeister In the meantime, do you know of any examples of an app using this library making use of those or similar declarations? Thanks!

from web3-react.

pcowgill avatar pcowgill commented on May 19, 2024

This seems to work for an app using this lib:

ErrorWithCode.ts

export interface ErrorWithCode extends Error {
  code?: string | number | undefined;
}

MyComponent.tsx

import { ErrorWithCode } from "[insert-path-here]/types/ErrorWithCode";
const {
    active,
    error,
    setConnector,
    setError
  }: {
    active: boolean;
    error?: ErrorWithCode | null;
    setConnector: any;
    setError: any;
  } = useWeb3Context();

(The any type for the functions isn't good TypeScript, but left it like that since that's not the focus here.)

from web3-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.