Unable to display a custom error message when overriding the default bulk delete route

Feature(s) impacted

Default routes.

Observed behavior

I’m returning a custom error message and it’s not appearing in the orange notification. The basic default error message is displayed
Events deletion failed: unexpected error.

Expected behavior

My custom error message should be displayed. I’ve read this topic and there’s something wrong because I’m reproducing it properly: Show error text in orange error popup when error on route
The only difference is that I’m using the default /delete route, which receives in body parameters a list of ids

Context

  • Project name: Back Office TR
  • Team name: the-ring.io
  • Environment name: Development

Here’s my code:

router.delete('/', async (req, res) => {
    const { ids } = req.body.data.attributes;

    if (!ids.length) {
       res.sendStatus(200);
       return;
    }

    const result = await deleteEventsRequest({
        request: req,
        ids,
    });

    if (result.error) {
        res.status(result.status).send(result.message);
        return;
    }

    res.sendStatus(200);
});

Moreover, if there are some good practices to know, I’m open :slight_smile:

Best regards,

Try with this :
res.status(result.status).send({ error: result.message});

I’ve already tried with this and it didn’t work. I’ve also tried with

res.status(result.status).send({ message: result.message});

and it also didn’t work.

Ok it seems that the patch deployed is no longer active.

The patch for batch delete is currently under review and should be released this week. - arnaud
Show error text in orange error popup when error on route - #9 by arnaud

Hey @KamilH, and welcome to our community :wave:

Could you please share the value of result.status you are using when triggering this issue?

From what I know, not all HTTP error code are handled by the toastr displayed when an issue happens.

Eventually, could you try forcing the error to be res.status(400).send({ error: result.message });, just to see if the behavior you are having it tied to the HTTP response sent by your agent? :pray:

I reproduce the bug with this basic code, and i have the same issue. It still display the default error message

response.status(400).send({ error: 'this is a specific error!' });

Response header:

HTTP/1.1 400 Bad Request
X-Powered-By: Express
Access-Control-Allow-Origin: https://app.forestadmin.com
Vary: Origin
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
Content-Length: 37
ETag: W/"25-4ZP+SqHGS3aOdakPagoe/Vr5xBc"
Date: Mon, 25 Apr 2022 13:04:04 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Response data :

{
    "error": "this is a specific error!"
}

@jeffladiray I’ve tried few different status codes : 400, 401, 403. None worked.

@Justin_Martin Well, it seems like there was a rollback ?

@KamilH
Yes it looks like. As an external, we only have access to the forestadmin backend repo. So, I’ll let forestadmin support check this

@Justin_Martin Alright, thank you very much !

Hey guys,

You just need to throw an error. And the message inside will be the error displayed :wink:

Hello @vince ,

It doesn’t work aswell. :confused:

Moreover, in case you throw an error in the back-end, the front wouldn’t be notified of it because the back-end will simply crash if the error is not handled and no response will be sent.

Hmm it works perfectly fine on my side :thinking:

Could you try the following otherwise:

router.delete('/', async (req, res, next) => {
  next(new Error('The message to print'));
});

Well, it doesn’t on mine :frowning:

if (result.error) {
   next(new Error(result.message)); // the error is present when analyzing network requests, but not displayed in the toast
   return;
}

The toast still displays Events deletion failed: unexpected error.

EDIT: can’t even change the success toast’ text when sending a 200

    res.status(200).send(`The event has been deleted`);

It still shows Event deleted

Can you send the entire code of your route :pray: ?
Is it the correct route :thinking: ?

Yes, it’s the correct route. It is properly called when doing the bulk delete request.

Here’s the entire code


router.delete('/', async (req, res, next) => {
    const { ids } = req.body.data.attributes;

    if (!ids.length) {
       res.sendStatus(200);
       return;
    }

    const result = await deleteEventsRequest({
        request: req,
        ids,
    });

    if (result.error) {
        next(new Error(result.message));
        return;
        // res.status(result.status).send({ error: result.message });
    }

    res.status(200).send(`The event has been deleted`);
});

Did you try doing a console.log just before the next to make sure it is called :person_shrugging: ?

What agent are you using by the way :thinking: ?

Yes, the next function has been called.
I’m using Chromium, doing the request from the ForestAdmin’s back-office. (https://app.forestadmin.com/MY_PROJECT/…)

Yeah sorry I meant, are you using forest-express-sequelize / forest-express-mongoose / etc… ? And what versions are you using ?

I’m using forest-express-sequelize@8.5.3

Do you have any custom middlewares that could catch the error :thinking: ?