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

**URL:** <https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538>\
**Category:** Help me!\
**Created:** [April 25, 2022, 12:43pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538 "2022-04-25T12:43:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 25, 2022, 12:43pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/1 "2022-04-25T12:43:13Z")

</div>

## 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](https://community.forestadmin.com/t/show-error-text-in-orange-error-popup-when-error-on-route/303)  
> 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](http://the-ring.io)
- Environment name: Development

Here’s my code:

```javascript
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 🙂

Best regards,

---

<div class="post-metadata">

**Author:** ![Justin\_Martin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/justin_martin/32/1028_2.png) [@Justin\_Martin](https://community.forestadmin.com/u/Justin_Martin)\
**Post date:** [April 25, 2022, 12:45pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/2 "2022-04-25T12:45:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 25, 2022, 12:47pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/3 "2022-04-25T12:47:25Z")

</div>

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

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

```

and it also didn’t work.

---

<div class="post-metadata">

**Author:** ![Justin\_Martin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/justin_martin/32/1028_2.png) [@Justin\_Martin](https://community.forestadmin.com/u/Justin_Martin)\
**Post date:** [April 25, 2022, 1:01pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/4 "2022-04-25T13:01:20Z")

</div>

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](https://community.forestadmin.com/t/show-error-text-in-orange-error-popup-when-error-on-route/303/9)

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [April 25, 2022, 1:02pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/5 "2022-04-25T13:02:05Z")

</div>

Hey @KamilH, and welcome to our community 👋

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? 🙏

---

<div class="post-metadata">

**Author:** ![Justin\_Martin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/justin_martin/32/1028_2.png) [@Justin\_Martin](https://community.forestadmin.com/u/Justin_Martin)\
**Post date:** [April 25, 2022, 1:04pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/6 "2022-04-25T13:04:21Z")

</div>

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:**

```javascript
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 :**

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

```

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 25, 2022, 1:07pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/7 "2022-04-25T13:07:29Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Justin\_Martin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/justin_martin/32/1028_2.png) [@Justin\_Martin](https://community.forestadmin.com/u/Justin_Martin)\
**Post date:** [April 25, 2022, 1:13pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/8 "2022-04-25T13:13:12Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 25, 2022, 1:14pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/9 "2022-04-25T13:14:11Z")

</div>

@Justin_Martin Alright, thank you very much !

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 25, 2022, 4:07pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/10 "2022-04-25T16:07:45Z")

</div>

Hey guys,

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

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 26, 2022, 5:32am UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/11 "2022-04-26T05:32:40Z")

</div>

Hello @anon62739609 ,

It doesn’t work aswell. 😕

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.

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 26, 2022, 7:44am UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/12 "2022-04-26T07:44:56Z")

</div>

Hmm it works perfectly fine on my side 🤔

Could you try the following otherwise:

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

```

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 26, 2022, 7:50am UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/13 "2022-04-26T07:50:53Z")

</div>

Well, it doesn’t on mine ☹

```javascript
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

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

```

It still shows `Event deleted`

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 26, 2022, 1:08pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/14 "2022-04-26T13:08:12Z")

</div>

Can you send the entire code of your route 🙏 ?  
Is it the correct route 🤔 ?

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 26, 2022, 2:42pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/15 "2022-04-26T14:42:28Z")

</div>

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

Here’s the entire code

```javascript

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`);
});

```

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 27, 2022, 9:25am UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/17 "2022-04-27T09:25:43Z")

</div>

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

What agent are you using by the way 🤔 ?

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 27, 2022, 9:30am UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/18 "2022-04-27T09:30:18Z")

</div>

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/](https://app.forestadmin.com/MY_PROJECT/)…)

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 27, 2022, 11:59am UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/19 "2022-04-27T11:59:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KamilH](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kamilh/32/4363_2.png) [@KamilH](https://community.forestadmin.com/u/KamilH)\
**Post date:** [April 27, 2022, 12:03pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/20 "2022-04-27T12:03:15Z")

</div>

I’m using `forest-express-sequelize@8.5.3`

---

<div class="post-metadata">

**Author:** ![anon62739609](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anon62739609](https://community.forestadmin.com/u/anon62739609)\
**Post date:** [April 27, 2022, 12:17pm UTC](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538/21 "2022-04-27T12:17:33Z")

</div>

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

[Next page](https://community.forestadmin.com/t/unable-to-display-a-custom-error-message-when-overriding-the-default-bulk-delete-route/4538.md?page=2)
