Commit be797a4e authored by Ben Boeckel's avatar Ben Boeckel
Browse files

error: split Error type into its own module

parent 0c1fb963
extern crate ease;
use self::ease::Error as EaseError;
extern crate serde_json;
use self::serde_json::Value;
extern crate url;
use self::url::ParseError as UrlError;
use std::error;
use std::fmt::{self, Display, Formatter};
#[derive(Debug)]
pub enum Error {
EaseError(EaseError),
UrlError(UrlError),
GitlabError(String),
}
impl Error {
pub fn from_gitlab(value: Value) -> Self {
let msg = value.pointer("/message")
.and_then(|s| s.as_string())
.unwrap_or_else(|| "unknown error");
Error::GitlabError(msg.to_owned())
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Error::EaseError(ref error) => write!(f, "ease error: {:?}", error),
Error::UrlError(ref error) => write!(f, "url error: {}", error),
Error::GitlabError(ref error) => write!(f, "gitlab error: {}", error),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
"GitLab API error"
}
fn cause(&self) -> Option<&error::Error> {
match *self {
Error::EaseError(ref error) => Some(error),
Error::UrlError(ref error) => Some(error),
_ => None,
}
}
}
impl From<EaseError> for Error {
fn from(error: EaseError) -> Self {
Error::EaseError(error)
}
}
impl From<UrlError> for Error {
fn from(error: UrlError) -> Self {
Error::UrlError(error)
}
}
......@@ -6,65 +6,11 @@ extern crate serde_json;
use self::serde_json::Value;
extern crate url;
use self::url::ParseError as UrlError;
use self::url::percent_encoding::{PATH_SEGMENT_ENCODE_SET, percent_encode};
use std::borrow::Borrow;
use std::error::Error as StdError;
use std::fmt::{self, Display, Formatter};
#[derive(Debug)]
pub enum Error {
EaseError(EaseError),
UrlError(UrlError),
GitlabError(String),
}
impl Error {
fn from_gitlab(value: Value) -> Self {
let msg = value.pointer("/message")
.and_then(|s| s.as_string())
.unwrap_or_else(|| "unknown error");
Error::GitlabError(msg.to_owned())
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Error::EaseError(ref error) => write!(f, "ease error: {:?}", error),
Error::UrlError(ref error) => write!(f, "url error: {}", error),
Error::GitlabError(ref error) => write!(f, "gitlab error: {}", error),
}
}
}
impl StdError for Error {
fn description(&self) -> &str {
"GitLab API error"
}
fn cause(&self) -> Option<&StdError> {
match *self {
Error::EaseError(ref error) => Some(error),
Error::UrlError(ref error) => Some(error),
_ => None,
}
}
}
use super::error::Error;
impl From<EaseError> for Error {
fn from(error: EaseError) -> Self {
Error::EaseError(error)
}
}
impl From<UrlError> for Error {
fn from(error: UrlError) -> Self {
Error::UrlError(error)
}
}
use std::borrow::Borrow;
#[derive(Clone, Copy)]
pub enum CommitStatus {
......
......@@ -5,7 +5,8 @@
#[macro_use]
extern crate hyper;
mod error;
mod gitlab;
pub use gitlab::Error;
pub use error::Error;
pub use gitlab::Gitlab;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment