File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ mod tests {
114114 method : HttpMethod :: Get ,
115115 path : PathTemplate :: new ( "/repos/{owner}/{repo}/issues" ) . unwrap ( ) ,
116116 base_url : BaseUrl :: new ( "https://api.github.com" ) . unwrap ( ) ,
117- accept : AcceptHeader :: new ( "application/json" ) ,
117+ accept : AcceptHeader :: new ( "application/json" ) . unwrap ( ) ,
118118 response_wrapper_key : None ,
119119 } ,
120120 }
Original file line number Diff line number Diff line change @@ -316,10 +316,15 @@ impl fmt::Display for HttpMethod {
316316pub struct AcceptHeader ( String ) ;
317317
318318impl AcceptHeader {
319- pub fn new ( s : impl Into < String > ) -> Self {
319+ pub fn new ( s : impl Into < String > ) -> Result < Self , Error > {
320320 let s = s. into ( ) ;
321- assert ! ( !s. is_empty( ) , "AcceptHeader cannot be empty" ) ;
322- Self ( s)
321+ if s. is_empty ( ) {
322+ return Err ( Error :: InvalidAcceptHeader {
323+ input : s,
324+ reason : "cannot be empty" ,
325+ } ) ;
326+ }
327+ Ok ( Self ( s) )
323328 }
324329
325330 pub fn as_str ( & self ) -> & str {
Original file line number Diff line number Diff line change @@ -312,7 +312,7 @@ mod tests {
312312 method : HttpMethod :: Get ,
313313 path : PathTemplate :: new ( "/test" ) . unwrap ( ) ,
314314 base_url : BaseUrl :: new ( "https://example.com" ) . unwrap ( ) ,
315- accept : AcceptHeader :: new ( "application/json" ) ,
315+ accept : AcceptHeader :: new ( "application/json" ) . unwrap ( ) ,
316316 response_wrapper_key : None ,
317317 } ,
318318 }
Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ mod tests {
215215 method : HttpMethod :: Get ,
216216 path : PathTemplate :: new ( "/test/{id}" ) . unwrap ( ) ,
217217 base_url : BaseUrl :: new ( "https://example.com" ) . unwrap ( ) ,
218- accept : AcceptHeader :: new ( "application/json" ) ,
218+ accept : AcceptHeader :: new ( "application/json" ) . unwrap ( ) ,
219219 response_wrapper_key : None ,
220220 } ,
221221 }
Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ pub enum Error {
2020 #[ error( "invalid base URL {input:?}: {reason}" ) ]
2121 InvalidBaseUrl { input : String , reason : & ' static str } ,
2222
23+ #[ error( "invalid accept header {input:?}: {reason}" ) ]
24+ InvalidAcceptHeader { input : String , reason : & ' static str } ,
25+
2326 // ---- Catalog lookup ----
2427 #[ error( "table {0} not found in catalog" ) ]
2528 TableNotFound ( TableName ) ,
Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ fn try_build_table(
165165 method : HttpMethod :: Get ,
166166 path : path_template,
167167 base_url : base_url. clone ( ) ,
168- accept : crate :: catalog:: types:: AcceptHeader :: new ( content_type) ,
168+ accept : crate :: catalog:: types:: AcceptHeader :: new ( content_type) ? ,
169169 response_wrapper_key : wrapper_key,
170170 } ,
171171 } ) )
You can’t perform that action at this time.
0 commit comments