Giter VIP home page Giter VIP logo

Comments (3)

gempain avatar gempain commented on June 1, 2024

You're absolutely right, the current frontend error management lacks the ability to extract error messages from backend errors. The reason is we're doing toast.error(Could not create org: ${err}); which converts the error object to a string via a JS string template, only extracting the Error.message (native behavior of error.toString()) instead of actually extracting the message from the backend response. These errors are actually axios errors and the backend message can be retrieved from error.response.data.message. A safe option would be to do it this way: toast.error(Could not create org: ${error.response?.data?.message || error.message});. But I would extract this to a function to generalize the error handling behavior across the app.

As Meli is meant to be deployed on your VPS, 1 is a sane default, as we expect that you most likely not want your users to create more organizations.

from meli.

mtiller avatar mtiller commented on June 1, 2024

@gemapin It appears somebody already did "extract this to a function". It is called extractExrrorMessage and it can be found in ui/src/utils/extract-exrror-message. I thought the name of the file was a typo until I saw it matches the name of the function. Is this a typo? I don't see why the extra x is in there. But in any case, this appears to be the function to use to extract an error message generically. I can submit a pull request with all the toast calls invoking this function. But do you want me to rename this function while I'm at it?!?

from meli.

gempain avatar gempain commented on June 1, 2024

Oh yes that's right, I think I created this function and left that aside for some reason. You can definitely reuse that and make the changes you suggested. You can also rename the function, it's a typo 😅 . I'd change the function however, because I realize that the response.data.message is potentially null, so to be safe here's what I'd do:

import { AxiosError } from 'axios';

export function extractErrorMessage(err: any) {
  let message: string;
  if (err.isAxiosError) {
    message = (err as AxiosError).response?.data?.message;
  }
  return message || err.message;
}

from meli.

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.