I'm currently working on a front end task that involves displaying API responses on the UI. The challenge I'm facing is that my API response contains messages with '\n' characters. Whenever '\n' appears, I want to create a new line so that any data following '\n' in the APIs is displayed on a separate line.
Here is the format of the response I receive from my REST API:
{"errors":[{"code":"rm.config.unableToSet",
"innerError":"memoery xyz has no labels\nResource abc is in use and cannot be removed",
"logref":"c8a6f244-188e-4512-85c1-88788","message":"\"Unable to set data to DB\""}]}
Attached is a screenshot for reference.
https://i.sstatic.net/f59fOUI6.png
The issue lies in the 'innerError' field where '\n' is present. This message is intended to be displayed on the UI in a popup.
I've attempted the following methods:
1. innerError = innerError.replace(/\n/g, "<br>")
After applying the above method, the data displays correctly on the console. However, it fails to render properly on the UI.
2. I initially replaced '\n' with <br>, then reverted it back to '\n'.
As shown in the screenshot, the data is retrieved but doesn't appear on a new line as expected.
If anyone can suggest a solution to meet this requirement, I would greatly appreciate it.
Thank you in advance!