Return custom error message within overridden default route

Hey Forest!

I’ve overriden the default put route on a table and would like to return a custom error message similar to that of a smart action. However I get this message instead. I get the correct message in the network response.

What can I do to fix this issue? Thank you in advance!

image

router.put('/subscriptions/:recordId', permissionMiddlewareCreator.update(), async (request, response, next) => {
  const { body, params, query, user } = request;
  const recordUpdater = new RecordUpdater(subscriptions, user, query);
  const sub = await subscriptions.findByPk(request.params.recordId);

  if(request.body.data.attributes.minChargePoints && sub.state === 'active') {
    return response.status(400).send({error: 'Cannot edit min charge points once subscription is active!'});
  }

  recordUpdater.deserialize(body)
    .then(recordToUpdate => recordUpdater.update(recordToUpdate, params.recordId))
    .then(record => recordUpdater.serialize(record))
    .then(recordSerialized => response.send(recordSerialized))
    .catch(next);
});

We can’t ensure that this will stay like this, as AFAIK this is not part of the public API, but the following response should do what you want:

{ errors: [{ detail: "Hi there!" }] };
1 Like

Hey @anon39940173,

Thank you! It worked.

1 Like