Show error text in orange error popup when error on route

Expected behavior

I want to show the error text I throw in the orange error popup. I talk about extended routes.

Actual behavior

When I’ve got an error in a collection (Users here), Forest produce this error text : Users deletion failed: unexpected error. instead the text error I pass in the next.

For instance, in your documentation, it’s possible to throw a specific error text, but it never appears in the orange error popup:

router.delete('/companies/:recordId', permissionMiddlewareCreator.delete(), (request, response, next) => {
  if (request.params.recordId === 82) {
    next(new Error('This record is protected, you cannot remove it.'));
    return;
  }

  const recordRemover = new RecordRemover(companies);
  recordRemover.remove(request.params.recordId)
    .then(() => response.status(204).send())
    .catch(next);
});

Hi @XavierColombel,

I think the documentation is not up-to-date.
I’ll report this.

The following implementation should work as expected:

router.delete('/companies/:recordId', permissionMiddlewareCreator.delete(), (request, response, next) => {
  if (request.params.recordId === 82) {
    response.status(403).send('This record is protected, you cannot remove it.');
    return;
  }

  const recordRemover = new RecordRemover(companies);
  recordRemover.remove(request.params.recordId)
    .then(() => response.status(204).send())
    .catch(next);
});

No, it doesn’t work. I mean, you can’t specify a text for the error.

For instance, if you have this route:

router.delete(
  "/users",
  permissionMiddlewareCreator.delete(),
  (request, response, next) => {
    return response.status(400).send("this is a specific error!");
  },
);

You’ll have the default error message:

User deletion failed: unexpected error.

Hi Xavier,

I’ve just redone this test-case: it displays well the message error.

This minimal example:

Produce this error message:

And output hello in my server log.
Can you have a try with this minimal hack?
(I ask myself if maybe you didn’t pass the permission middleware?)

Regards

1 Like

@Sliman_Medini your example is working beacause you use the route router.delete("/user/:recordId"..., but try with the route router.delete("/user", permissionMiddlewareCreator.delete() without the recordId in the route.

Hi Xavier,

You are right, I reproduce your problem on a bulk route ("/user")

This minimal example:

Produce this error message:

Instead of displaying “big error here”
I am creating a bug entry to handle this.

Regards

Thank you @Sliman_Medini

Hi @XavierColombel,

The patch for batch delete is currently under review and should be released this week.

Wow nice! Thanks @arnaud. Can’t wait. :smiley:

1 Like

The patch is now live.
You just have to refresh you browser page to benefit from it.

Thanks @arnaud ! I’ll test later. :+1: