Fixed a bug in the rest code that was triggered in error handling
made changes to make the error reporting from REST calls more accurate