I have XML error returned from the server, which the snippet of the interest part of the error is like this:
...
<p class="break-long-words trace-message">SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "name" violates not-null constraint<br />
DETAIL: Failing row contains (165, null, null, 11, null, 2018-04-19 03:01:48, null, f, 6).</p>
...
Because this happens often during development, I want to make it easier for me to scan for this particular error message and report it to the backend team. So from the error like above, I conclude that I can confidently get the substring that begins with SQLSTATE
and ends before </p>
. So the cleaned error will be:
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "name" violates not-null constraint<br />
DETAIL: Failing row contains (165, null, null, 11, null, 2018-04-19 03:01:48, null, f, 6).
The question is, how to do that in Swift? The XML error is not just this only. I just cut out the point of interest. But there will be a plethora of <p></p>
tags.