Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
How to display server side validation errors with onFailure() in Edit/Create components?

I'd like to display server errors in notifications. By default, the notification says "Bad request" when a 400 is returned. I've tried to change the behaviour with the onFailure (https://marmelab.com/react-admin/CreateEdit.html#onfailure), but the argument error always seems to be a generic HttpError(). The message is lost somewhere, somehow.


export const MyEdit = (props) => {
  const refresh = useRefresh();

  const onFailure = (error) => {
    console.log('ERROR stack trace', error);  // show 'Error'
    console.log('ERROR stack trace', error.stack);  // show 'Error'
    refresh();
  };


  return (
    <Edit
      onFailure={onFailure}
      {...props}
    >
      <SimpleForm>
        <TextInput
          source="full_name"
          fullWidth
        />
        <TextInput
          source="email"
          fullWidth
        />
      </SimpleForm>
    </Edit>
  );
};

The response on the server side is usually something like that

{
  field: [
    error_message_1,
    error_message_2,
    ...,
    error_message_n
  ]
}

With the Chrome debugger, it seems that my problem should come this class:


var HttpError = /** @class */ (function (_super) {
    __extends(HttpError, _super);
    function HttpError(message, status, body) {
        if (body === void 0) { body = null; }
        var _this = _super.call(this, message) || this;
        _this.message = message;
        _this.status = status;
        _this.body = body;
        Object.setPrototypeOf(_this, HttpError.prototype);
        _this.name = _this.constructor.name;
        if (typeof Error.captureStackTrace === 'function') {
            // Enter here
            Error.captureStackTrace(_this, _this.constructor);
        }
        else {
            _this.stack = new Error(message).stack;
        }
        // Returns an empty Error();
        _this.stack = new Error().stack;
        return _this;
    }
    return HttpError;
}(Error));

It returns an empty Error() and the stack does not contain values of previous message, body or status.

So how can I display the server message? Any help would be appreciated.

Just in case: Chrome 95: React-Admin: 3.19

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Found the answer.

I tried error, error.message and error.stack but I did not try error.body. It became obvious after re-reading my question.

error.body does return the back-end JSON response.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda