Extracting message data
We can extract data from the message and put it in appropriate fields.
Remember what was said about a descriptive error message that was generated but not used? We can search in it for the name of the entity that was not found. It can be found between double quotes, after the word "type". We can then extract this name with the following regex:
Let's then create a private method that extracts the entity name from the message
. As we only expect a single result, we access the first index.
As a small encapsulation improvement, we could create a function to perform this extraction, in common/util/regex.util.
And use it to obtain the entityName
.
Then, once again in the catch()
method, extract this name from the descriptive message
.
And finally, create the message that will actually be returned.
The only thing that's left to do now is to setup the response.
Last updated