-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed reqwest cookies feature. Added custom error. Added reqwest client.
- Loading branch information
Showing
7 changed files
with
101 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::error; | ||
use std::fmt; | ||
|
||
/// An error that can occur in this library. | ||
/// | ||
/// Usually errors are when trying to send a request to the SolarEdge server, | ||
/// or when trying to parse the response from the server. | ||
#[derive(Debug)] | ||
pub struct Error { | ||
kind: ErrorKind, | ||
} | ||
|
||
impl Error { | ||
pub(crate) fn new(kind: ErrorKind) -> Error { | ||
Error { kind } | ||
} | ||
|
||
/// Convenience function for getting the kind of error. | ||
pub fn kind(&self) -> &ErrorKind { | ||
&self.kind | ||
} | ||
} | ||
|
||
/// The different kinds of errors that can occur. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum ErrorKind { | ||
/// An error returned from the reqwest crate. | ||
ReqwestError(reqwest::Error), | ||
} | ||
|
||
impl error::Error for Error { | ||
fn description(&self) -> &str { | ||
match self.kind { | ||
ErrorKind::ReqwestError(_) => "Reqwest error", | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match &self.kind { | ||
ErrorKind::ReqwestError(s) => write!(f, "Reqwest Error: HTTP status-code{}", s), | ||
} | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for Error { | ||
fn from(e: reqwest::Error) -> Self { | ||
Error::new(ErrorKind::ReqwestError(e)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters