impl Error for AllowedUrlError

parent 26c3b086
use std::error::{self, Error};
use std::fmt;
use std::io;
use std::path::{Path, PathBuf};
use url::{self, Url};
......@@ -108,6 +110,30 @@ impl AllowedUrl {
}
}
impl error::Error for AllowedUrlError {
fn description(&self) -> &str {
match *self {
AllowedUrlError::HrefParseError(_) => "href parse error",
AllowedUrlError::BaseRequired => "base required",
AllowedUrlError::DifferentURISchemes => "different URI schemes",
AllowedUrlError::DisallowedScheme => "disallowed scheme",
AllowedUrlError::NotSiblingOrChildOfBaseFile => "not sibling or child of base file",
AllowedUrlError::InvalidPath => "invalid path",
AllowedUrlError::BaseIsRoot => "base is root",
AllowedUrlError::CanonicalizationError => "canonicalization error",
}
}
}
impl fmt::Display for AllowedUrlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
AllowedUrlError::HrefParseError(e) => write!(f, "{}: {}", self.description(), e),
_ => write!(f, "{}", self.description()),
}
}
}
// For tests, we don't want to touch the filesystem. In that case,
// assume that we are being passed canonical file names.
#[cfg(not(test))]
......
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