Error is not correct

I want just this error : Pour modifier un sinistre, merci de bien renseigner le champ “Autre type de sinistre”. but I have this error :
image

Observed behavior

router.put(‘/damages/:id’, permissionMiddlewareCreator.update(), (request, response, next) => {
// Learn what this route does here: v9 (v1 Django/Laravel)
const { query, user } = request;
const recordUpdater = new RecordUpdater(models.damages,user, query);
const id = request.params.id;
const data = request.body.data.attributes;
let body = { damage: {} };

if (data.description) { body.damage.description = data.description; }
if (data.kind) { body.damage.kind = data.kind; }
// if (data.declarant_id) { body.damage. = data. ;}
if (data.damageDescription) { body.damage.damage_description = data.damageDescription; }
if (data.cause) { body.damage.cause = data.cause === ‘’ ? null : data.cause; }
//if (data.kind) { body.place.kind = data.kind === ‘’ ? null : data.kind; }
if (data.insuranceReference) { body.damage.insurance_reference = data.insuranceReference; }
if (data.repairing) { body.damage.repairing = data.repairing; }
if (data.step) { body.damage.step = data.step; }
//if (data.otherType) { body.damage.other_type = data.otherType; }

if (data.kind===‘other’) {
body.damage.other_type= data.otherType;
}

if (data.kind === ‘other’ && !(data.otherType)) {

response.status(400).send(
'Pour modifier un sinistre, merci de bien renseigner le champ "Autre type de sinistre".'
); 

}
else {
axios.put(${API_URL}/forest_admin/damages/${id}, body, {
headers: {
‘Authorization’: Bearer ${process.env.ACCESS_TOKEN},
‘X-CURRENT-USER-EMAIL’: request.user.email
}
}).then(async res => {
response.send(await recordUpdater.serialize(res.data));
}).catch(err => {
console.log(“:rocket: ~ err:”, err)
if (err.response?.data?.error?.message) {
response.status(400).send(err.response.data.error.message);
} else {
response.status(400).send(‘Erreur inattendue, veuillez contacter votre administrateur.’);
}
});
}

});

Context

Project name: .Sergic
Team name: gestion
Environment name: Développement
Agent (forest package) name & version: 9
Database type: Postgres
Recent changes made on your end if any: upgrade to v9

Hello,
Can you tell us more details about your bugs. In your description, you ask to have this error: “Pour modifier un sinistre, merci de bien renseigner le champ “Autre type de sinistre”” but in the screenshot it’s the same error.
Also, can you format your code when you share it please :pray: It help us a lot.

I don’have the first message "Ann error occured when trying to edit sinistre "
I want just this message:
if (data.kind === ‘other’ && !(data.otherType)) {

response.status(400).send(
'Pour modifier un sinistre, merci de bien renseigner le champ "Autre type de sinistre".'
);
router.put('/damages/:id', permissionMiddlewareCreator.update(), (request, response, next) => {
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#update-a-record
  const { query, user } = request;
  const recordUpdater = new RecordUpdater(models.damages,user, query);
  const id = request.params.id;
  const data = request.body.data.attributes;
  let body = { damage: {} };

  if (data.description) { body.damage.description = data.description; }
  if (data.kind) { body.damage.kind = data.kind; }
  // if (data.declarant_id) { body.damage. = data. ;}
  if (data.damageDescription) { body.damage.damage_description = data.damageDescription; }
  if (data.cause) { body.damage.cause = data.cause === '' ? null : data.cause; }
  //if (data.kind) { body.place.kind = data.kind === '' ? null : data.kind; }
  if (data.insuranceReference) { body.damage.insurance_reference = data.insuranceReference; }
  if (data.repairing) { body.damage.repairing = data.repairing; }
  if (data.step) { body.damage.step = data.step; }
  //if (data.otherType) { body.damage.other_type = data.otherType; }
  
  
  if (data.kind==='other') {
      body.damage.other_type= data.otherType;
  }

  if (data.kind === 'other' && !(data.otherType)) {
   
    response.status(400).send(
    'Pour modifier un sinistre, merci de bien renseigner le champ "Autre type de sinistre".'
    ); 
    
   
  } 
  else {
    axios.put(`${API_URL}/forest_admin/damages/${id}`, body, {
      headers: {
        'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
        'X-CURRENT-USER-EMAIL': request.user.email
      }
    }).then(async res => {
      response.send(await recordUpdater.serialize(res.data));
    }).catch(err => {
      console.log("🚀 ~ err:", err)
      if (err.response?.data?.error?.message) {
        response.status(400).send(err.response.data.error.message);
      } else {
        response.status(400).send('Erreur inattendue, veuillez contacter votre administrateur.');
      }
    });
  }

});

I understand your needs but it’s not possible unfortunately. If you want to custom all the message validation It’s preferable to use smart action with form. In your case, when you overriding a route, it’s not possible :confused:

I will push your feedback to our product board :slight_smile:

1 Like