Verified Commit 155a3a53 authored by Grokafar's avatar Grokafar
Browse files

Use external crate `url` for ParseError

parent b66cab74
......@@ -20,6 +20,7 @@ percent-encoding = "^2.0"
reqwest = { version = "~0.10", features = ["blocking", "json"] }
rustversion = "^1.0"
thiserror = "^1.0.2"
url = "2.1"
chrono = { version = "~0.4", features = ["serde"] }
graphql_client = "~0.8"
......
......@@ -14,14 +14,13 @@ use crates::itertools::Itertools;
use crates::percent_encoding::{utf8_percent_encode, AsciiSet, PercentEncode, CONTROLS};
use crates::reqwest::blocking::{Client, RequestBuilder};
use crates::reqwest::header::{self, HeaderValue};
use crates::reqwest::IntoUrl;
use crates::reqwest::Url;
use crates::serde::de::Error as SerdeError;
use crates::serde::de::{DeserializeOwned, Unexpected};
use crates::serde::ser::Serialize;
use crates::serde::{Deserialize, Deserializer, Serializer};
use crates::serde_json;
use crates::thiserror::Error;
use crates::url::{self, Url};
use types::*;
......@@ -93,6 +92,11 @@ impl Token {
#[derive(Debug, Error)]
// TODO #[non_exhaustive]
pub enum GitlabError {
#[error("failed to parse url: {}", source)]
UrlParse {
#[from]
source: url::ParseError,
},
#[error("no such user: {}", user)]
NoSuchUser { user: String },
#[error("error setting token header: {}", source)]
......@@ -255,10 +259,6 @@ enum CertPolicy {
Insecure,
}
fn parse_url<T: IntoUrl>(url: T) -> GitlabResult<Url> {
Ok(url.into_url()?)
}
impl Gitlab {
/// Create a new Gitlab API representation.
///
......@@ -334,8 +334,8 @@ impl Gitlab {
token: Token,
cert_validation: CertPolicy,
) -> GitlabResult<Self> {
let base_url: Url = parse_url(&format!("{}://{}/api/v4/", protocol, host))?;
let graphql_url = parse_url(&format!("{}://{}/api/graphql", protocol, host))?;
let base_url = Url::parse(&format!("{}://{}/api/v4/", protocol, host))?;
let graphql_url = Url::parse(&format!("{}://{}/api/graphql", protocol, host))?;
let client = match cert_validation {
CertPolicy::Insecure => {
......@@ -1995,11 +1995,7 @@ impl Gitlab {
U: AsRef<str>,
{
debug!(target: "gitlab", "api call {}", url.as_ref());
Ok(parse_url(&format!(
"{}/{}",
self.base_url.as_str(),
url.as_ref()
))?)
Ok(self.base_url.join(url.as_ref())?)
}
/// Create a URL to an API endpoint with query parameters.
......
......@@ -29,6 +29,7 @@ mod crates {
pub extern crate reqwest;
// pub extern crate rustversion;
pub extern crate thiserror;
pub extern crate url;
}
#[macro_use]
......
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