If the robots generate an error the result will be an HTML page and not XML or JSON, so you have to parse the HTML in order to get the error message, i suggest using reqex.
If you can identify the error inside the robot, you can handle it with the normal error handling, and the return an object that will be transformed into JSON, however since objects may have already been returned you will get both results and an error, so it may be better to just stop the robot when the error occurs (using the Stop step).