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 | |
parent | 32327b7dbe2a3515542d2913b99ddfba0ae96511 (diff) | |
download | git-suggestion-8e921835f8aa4f6650a5df151435675b82fb24c8.tar.bz2 |
Client::new(): Return a `Result`
Wrap `Github` client errors.
-rw-r--r-- | src/bin/git-sugapply.rs | 2 | ||||
-rw-r--r-- | src/bin/git-sugpatch.rs | 2 | ||||
-rw-r--r-- | src/client.rs | 14 |
3 files changed, 12 insertions, 6 deletions
diff --git a/src/bin/git-sugapply.rs b/src/bin/git-sugapply.rs index d569147..47d26f2 100644 --- a/src/bin/git-sugapply.rs +++ b/src/bin/git-sugapply.rs @@ -17,7 +17,7 @@ fn main() { env!("GITHUB_TOKEN"), &url.owner, &url.repo, - ); + ).unwrap(); let suggestion = client.fetch(&url.comment_id).unwrap(); diff --git a/src/bin/git-sugpatch.rs b/src/bin/git-sugpatch.rs index 08d1a38..1e21923 100644 --- a/src/bin/git-sugpatch.rs +++ b/src/bin/git-sugpatch.rs @@ -17,7 +17,7 @@ fn main() { env!("GITHUB_TOKEN"), &url.owner, &url.repo, - ); + ).unwrap(); let suggestion = client.fetch(&url.comment_id).unwrap(); 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> { |