diff options
author | Teddy Wing | 2020-07-28 23:22:55 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-28 23:23:39 +0200 |
commit | 8e921835f8aa4f6650a5df151435675b82fb24c8 (patch) | |
tree | c9b66ccf587a7361df88494fed6569a6c33e5949 /src/client.rs | |
parent | 32327b7dbe2a3515542d2913b99ddfba0ae96511 (diff) | |
download | git-suggestion-8e921835f8aa4f6650a5df151435675b82fb24c8.tar.bz2 |
Client::new(): Return a `Result`
Wrap `Github` client errors.
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/client.rs b/src/client.rs index 0625443..c6ae1f1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -22,10 +22,16 @@ pub struct Client<'a> { } impl<'a> Client<'a> { - pub fn new(token: &str, owner: &'a str, repo: &'a str) -> Self { - let client = Github::new(&token).unwrap(); - - Client { client, owner, repo } + pub fn new( + token: &str, + owner: &'a str, repo: &'a str, + ) -> Result<Self, Error> { + let client = match Github::new(&token) { + Ok(g) => g, + Err(e) => return Err(Error::Github(e.to_string())), + }; + + Ok(Client { client, owner, repo }) } pub fn fetch(&self, id: &str) -> Result<Suggestion, Error> { |