KamilH
April 25, 2022, 12:43pm
1
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
Best regards,
Try with this :
res.status(result.status).send({ error: result.message});
KamilH
April 25, 2022, 12:47pm
3
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
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?
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!"
}
KamilH
April 25, 2022, 1:07pm
7
@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
KamilH
April 25, 2022, 1:14pm
9
@Justin_Martin Alright, thank you very much !
vince
April 25, 2022, 4:07pm
10
Hey guys,
You just need to throw an error. And the message inside will be the error displayed
KamilH
April 26, 2022, 5:32am
11
Hello @vince ,
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.
vince
April 26, 2022, 7:44am
12
Hmm it works perfectly fine on my side
Could you try the following otherwise:
router.delete('/', async (req, res, next) => {
next(new Error('The message to print'));
});
KamilH
April 26, 2022, 7:50am
13
Well, it doesn’t on mine
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
vince
April 26, 2022, 1:08pm
14
Can you send the entire code of your route ?
Is it the correct route ?
KamilH
April 26, 2022, 2:42pm
15
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`);
});
vince
April 27, 2022, 9:25am
17
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 ?
KamilH
April 27, 2022, 9:30am
18
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/ …)
vince
April 27, 2022, 11:59am
19
Yeah sorry I meant, are you using forest-express-sequelize / forest-express-mongoose / etc… ? And what versions are you using ?
KamilH
April 27, 2022, 12:03pm
20
I’m using forest-express-sequelize@8.5.3
vince
April 27, 2022, 12:17pm
21
Do you have any custom middlewares that could catch the error ?