added error handling, fixed tests, added error handling test, refactored (https://github.com/restlet/apispark/issues/2225)