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

No.
The error is properly sent back to the ForestAdmin’s panel, but not displayed.
If I open my browser’s developer tools, click on the “Network” tab, then delete an event, a new request will be added in the network requests’ list.
If I click on the delete request and look at the “Response” tab, I see my error. So it is properly sent back to Forest but not displayed in the toastr.

Can you show me the response sent by your server :thinking: ?

> DELETE /forest/events HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 72
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 422 Unprocessable Entity
< X-Powered-By: Express
< Vary: Origin
< Access-Control-Allow-Credentials: true
< Content-Type: application/json; charset=utf-8
< Content-Length: 105
< ETag: W/"69-Q+t102f7gOX/ynGJ0Jd9HEuWh1s"
< Date: Wed, 27 Apr 2022 13:53:11 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
* Connection #0 to host localhost left intact
{"error":"L'événement ne peut être supprimé que si il n'y aucun participant à part l'organisateur."}%

For this one, I kept sending an object with an error property.

But here’s the code when I’m sending a simple string as error

> DELETE /forest/events HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 72
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 422 Unprocessable Entity
< X-Powered-By: Express
< Vary: Origin
< Access-Control-Allow-Credentials: true
< Content-Type: text/html; charset=utf-8
< Content-Length: 93
< ETag: W/"5d-1Y2ESxF1coBG9fJ3W/qi2FCXuSk"
< Date: Wed, 27 Apr 2022 13:54:11 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
* Connection #0 to host localhost left intact
L'événement ne peut être supprimé que si il n'y aucun participant à part l'organisateur.%

Could you try the following in you app.js

const { errorHandler, logger } = require('forest-express');

......

// this need to be the last app.use
app.use(errorHandler({ logger }));

module.exports = app;

It doesn’t working either :confused:

EDIT: OK, I’ve got it working using both your handler and the next() function.
But what is weird is that it shouldn’t require the next() function to be used, but I could send it using the response variable, retrieved during the Express request.
See: Overriden routes error management

Is there any way not to use the next() function but this response.status(400).send('error message'); ?
Because it seems working for @JeremyV

Using the errorHandler middleware prevents me from sending success custom message.

If you want to use the response.send which I do not recommend you need to serialize your error correctly:

response.send({
  errors: [{
    detail: 'The message to print',
  }],
})

Well it indeed works using this serialization.
It is less readable, I’m staying with the next() function.

Thanks for everything :slight_smile: