From 8e921835f8aa4f6650a5df151435675b82fb24c8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Jul 2020 23:22:55 +0200 Subject: Client::new(): Return a `Result` Wrap `Github` client errors. --- src/client.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/client.rs') 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 { + 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 { -- cgit v1.2.3