Improved error handling in Client

More test coverage and changed sample page so it uses file instead of session for token storage.