2506 - Added error handling for invalid json responses

- This change also works to fix bad 3xx redirects as noted in #2506.