Added error handling for full html and json responses, as well as general json responses (currently not smart and not safe)