Giter VIP home page Giter VIP logo

Comments (6)

simoneb avatar simoneb commented on June 12, 2024 1

I guess the additional configuration option is one possible way but it doesn't feel like it deserves so much attention at the current time, I would like to keep things simple. If there's demand for this feature I may reconsider it. Thanks for reporting though!

from axios-hooks.

DarynHolmes avatar DarynHolmes commented on June 12, 2024 1

I might just do this

const silenceError = (fn) => () => fn().catch(() => {})
    const [{ data, loading, error }, postLogin] = useAxios({
          url: '/login',
          method: 'POST'
        },
        { manual: true }
    )

    const login = silenceError(() => {
      return postLogin({
        data: {
          username,
          password
        }
      })
    })

from axios-hooks.

simoneb avatar simoneb commented on June 12, 2024

Fair point. It's been requested in #51 that the manual fetch function returns the promise, which makes sense to me because if you do a manual fetch you may also want more control about what happens when the promise resolves/rejects. But this also means that if there's a rejection and you're not interested into it you need to swallow it somehow.

Unfortunately I don't see a solution that can cover both cases. Ideas?

from axios-hooks.

DarynHolmes avatar DarynHolmes commented on June 12, 2024

I thought it might be a deliberate design choice. It can be quite nice to get the actual promise.

I guess you could pass in another option like this:

          url: '/login',
          method: 'POST'
        },
        { 
            manual: true,
            void: true // or returnPromise: false
         }
    )

There is no need to over complicate this for me, at the moment I am using:

const silenceError = (promise) => promise.catch(() => {})
...
...
...
    const login = () => {
      silenceError(postLogin({
        data: {
          username,
          password
        }
      }))
    }

from axios-hooks.

DarynHolmes avatar DarynHolmes commented on June 12, 2024

Or just catch the promise in a standard way....

Thanks again for the library.

from axios-hooks.

sujeet-agrahari avatar sujeet-agrahari commented on June 12, 2024

What if it throws 400, a bad request, and we want to show the error message to the user? I am having the same issue.

const [{ error }, executeUpdate] = axiosHook(
    {
      ...ApiConfig.COURSE.UPDATE_COURSE,
    },
    { manual: true }
  );

...and here I call executeUpdate. I thought error will be the updated error but that line,if (error) { ...do something },never gets executed as promise is rejected.

  const updateCourse = () => {
    handleSubmit(async (data) => {
      await executeUpdate({
        url: `${ApiConfig.COURSE.GET_COURSES.url}/${courseRow.id}`,
        data,
      });
      console.log(error);  // never gets called
      await refetchCourse();
    })();
  };

Is there a way we could silence the error from executeUpdate and get the error from state error variable instead?

from axios-hooks.

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.