How to send error message in Custom HTML response

From a Smart Action, I want to send custom HTML response when exception occurs.

try {
    let attrs = req.body.data.attributes.values;
    // process attrs here
    res.send({ success: 'Upload completed successfully!!' });
  } catch (e) {
    // Here - "e.message" has HTML content
    res.status(400).send({ html: `<div>${e.message}<div>`, error: 'Data Upload failed with above-mentioned errors.' });
  }

Expected behavior

The error message should be shown inside the Smart Action’s container along with the error message.

Actual behavior

Custom HTML is not getting displayed now. Only error message is being shown in the popbox.

Failure Logs

None.

Hello @Shriram_Balakrishnan,

Sorry but sending HTML with error responses is not currently supported.

A compromise would be to respond with a 200 and still include the error message in the HTML.

I’ll share your feedback with the team, and see if we can put this on the roadmap.

That is possible. But the downside in this case is that I need to pass the single-line status message in “success” as follows:

res.send({ html: `${e.message}`, success: 'FAILURE - Upload failed with above-mentioned errors.' });

But this shows the FAILURE message in pop-up with green background and tick mark that makes this looks like a success message.

Is there a workaround to show this success message in a RED background?

Not a the moment sorry.

I’ll keep you posted when this is available.

1 Like