Giter VIP home page Giter VIP logo

Comments (7)

k8n avatar k8n commented on August 13, 2024

I am noting that vuex-crud calls error handlers from inside mutations (e.g. onFetchListError).

As far as I understand it, dispatching actions from inside mutation goes against the vuex design principle.

So, I imagine, the way one should handle errors is to catch them inside components that call upon the store. E.g.

this.$store.dispatch('foo/fetchList')
  .then(function() { /* ... */ })
  .catch(function(parsedError) { /* ... dispatch actions to handle errors ... */ })

from vuex-crud.

JiriChara avatar JiriChara commented on August 13, 2024

Hey @martinhbramwell @k8n,

sorry for my late reply, but I was on holiday without my laptop :-).

onFetchListError, onFetchListSuccess are actually not meant to be an error handlers, but rather a simple callbacks to modify the store in a custom way.

And I agree with @k8n that you should handle errors using promises on your component level

from vuex-crud.

JiriChara avatar JiriChara commented on August 13, 2024

I will update the documentation, so it's more clear that there should be no side-effects in onFetchListError callbacks

from vuex-crud.

martinhbramwell avatar martinhbramwell commented on August 13, 2024

My requirements include keeping the user's browser console free of any errors or warnings.

I took your example and replaced those lines with

  onFetchArticles() {
    LG(' * * Try to fetch articles * *');
    this.fetchArticles()
      .then(() => { LG(' * * Fetched articles * *'); })
      .catch((e) => {
        LG(`*** Error while fetching articles :: ${e}***`);
      });
  },

When logged out and clicking Fetch articles I see :

* * Try to fetch articles * *
GET ...myserver/api/articles 401 (Unauthorized) .   .   .   xhr.js?ec6c:178`
*** Error while fetching articles :: Error: Request failed with status code 401***`

Where GET ...myserver/api/articles 401 (Unauthorized) . . . xhr.js?ec6c:178 is a big red line!

How can I completely clean up the console?

from vuex-crud.

JiriChara avatar JiriChara commented on August 13, 2024

@martinhbramwell I think those errors comes from default server logging see: axios/axios#599

I am really not sure if we can do anything about it. 🤔

from vuex-crud.

JiriChara avatar JiriChara commented on August 13, 2024

Also: https://stackoverflow.com/questions/41515732/hide-401-console-error-in-chrome-dev-tools-getting-401-on-fetch-call

from vuex-crud.

martinhbramwell avatar martinhbramwell commented on August 13, 2024

Right! Understood. Thanks for looking into it and thanks for clarifying.

from vuex-crud.

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.