@@ -149,41 +149,15 @@ impl Registry {
149149 pub fn add_owners ( & mut self , krate : & str , owners : & [ & str ] ) -> Result < String > {
150150 let body = serde_json:: to_string ( & OwnersReq { users : owners } ) ?;
151151 let body = self . put ( & format ! ( "/crates/{}/owners" , krate) , body. as_bytes ( ) ) ?;
152- let body = if body. is_empty ( ) {
153- r#"{"ok":false,"msg":"response body is empty"}"# . parse ( ) ?
154- } else {
155- body
156- } ;
157- match serde_json:: from_str :: < OwnerResponse > ( & body) {
158- Ok ( response) => {
159- if response. ok {
160- Ok ( response. msg )
161- } else {
162- bail ! ( "{}" , response. msg)
163- }
164- }
165- _ => bail ! ( "failed to parse response body" ) ,
166- }
152+ assert ! ( serde_json:: from_str:: <OwnerResponse >( & body) ?. ok) ;
153+ Ok ( serde_json:: from_str :: < OwnerResponse > ( & body) ?. msg )
167154 }
168155
169- pub fn remove_owners ( & mut self , krate : & str , owners : & [ & str ] ) -> Result < String > {
156+ pub fn remove_owners ( & mut self , krate : & str , owners : & [ & str ] ) -> Result < ( ) > {
170157 let body = serde_json:: to_string ( & OwnersReq { users : owners } ) ?;
171158 let body = self . delete ( & format ! ( "/crates/{}/owners" , krate) , Some ( body. as_bytes ( ) ) ) ?;
172- let body = if body. is_empty ( ) {
173- r#"{"ok":false,"msg":"response body is empty"}"# . parse ( ) ?
174- } else {
175- body
176- } ;
177- match serde_json:: from_str :: < OwnerResponse > ( & body) {
178- Ok ( response) => {
179- if response. ok {
180- Ok ( response. msg )
181- } else {
182- bail ! ( "{}" , response. msg)
183- }
184- }
185- _ => bail ! ( "failed to parse response body" ) ,
186- }
159+ assert ! ( serde_json:: from_str:: <OwnerResponse >( & body) ?. ok) ;
160+ Ok ( ( ) )
187161 }
188162
189163 pub fn list_owners ( & mut self , krate : & str ) -> Result < Vec < User > > {
@@ -298,21 +272,8 @@ impl Registry {
298272
299273 pub fn unyank ( & mut self , krate : & str , version : & str ) -> Result < ( ) > {
300274 let body = self . put ( & format ! ( "/crates/{}/{}/unyank" , krate, version) , & [ ] ) ?;
301- let body = if body. is_empty ( ) {
302- r#"{"ok":false}"# . parse ( ) ?
303- } else {
304- body
305- } ;
306- match serde_json:: from_str :: < R > ( & body) {
307- Ok ( response) => {
308- if response. ok {
309- Ok ( ( ) )
310- } else {
311- bail ! ( "ok is false in response body" )
312- }
313- }
314- _ => bail ! ( "failed to parse response body" ) ,
315- }
275+ assert ! ( serde_json:: from_str:: <R >( & body) ?. ok) ;
276+ Ok ( ( ) )
316277 }
317278
318279 fn put ( & mut self , path : & str , b : & [ u8 ] ) -> Result < String > {
0 commit comments