Improved error handling for non-json responses