Skip to content

Commit ee6e726

Browse files
authored
fix(transport): Endpoint returns transport error (#920)
1 parent 6bc7dab commit ee6e726

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

tonic/src/transport/channel/endpoint.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use super::ClientTlsConfig;
66
use crate::transport::service::TlsConnector;
77
use crate::transport::Error;
88
use bytes::Bytes;
9-
use http::{
10-
uri::{InvalidUri, Uri},
11-
HeaderValue,
12-
};
9+
use http::{uri::Uri, HeaderValue};
1310
use std::{
1411
convert::{TryFrom, TryInto},
1512
fmt,
@@ -76,8 +73,8 @@ impl Endpoint {
7673
/// # use tonic::transport::Endpoint;
7774
/// Endpoint::from_shared("https://example.com".to_string());
7875
/// ```
79-
pub fn from_shared(s: impl Into<Bytes>) -> Result<Self, InvalidUri> {
80-
let uri = Uri::from_maybe_shared(s.into())?;
76+
pub fn from_shared(s: impl Into<Bytes>) -> Result<Self, Error> {
77+
let uri = Uri::from_maybe_shared(s.into()).map_err(|e| Error::new_invalid_uri().with(e))?;
8178
Ok(Self::from(uri))
8279
}
8380

@@ -404,23 +401,23 @@ impl From<Uri> for Endpoint {
404401
}
405402

406403
impl TryFrom<Bytes> for Endpoint {
407-
type Error = InvalidUri;
404+
type Error = Error;
408405

409406
fn try_from(t: Bytes) -> Result<Self, Self::Error> {
410407
Self::from_shared(t)
411408
}
412409
}
413410

414411
impl TryFrom<String> for Endpoint {
415-
type Error = InvalidUri;
412+
type Error = Error;
416413

417414
fn try_from(t: String) -> Result<Self, Self::Error> {
418415
Self::from_shared(t.into_bytes())
419416
}
420417
}
421418

422419
impl TryFrom<&'static str> for Endpoint {
423-
type Error = InvalidUri;
420+
type Error = Error;
424421

425422
fn try_from(t: &'static str) -> Result<Self, Self::Error> {
426423
Self::from_shared(t.as_bytes())
@@ -434,7 +431,7 @@ impl fmt::Debug for Endpoint {
434431
}
435432

436433
impl FromStr for Endpoint {
437-
type Err = InvalidUri;
434+
type Err = Error;
438435

439436
fn from_str(s: &str) -> Result<Self, Self::Err> {
440437
Self::try_from(s.to_string())

0 commit comments

Comments
 (0)