@@ -149,41 +149,15 @@ impl Registry {
149
149
pub fn add_owners ( & mut self , krate : & str , owners : & [ & str ] ) -> Result < String > {
150
150
let body = serde_json:: to_string ( & OwnersReq { users : owners } ) ?;
151
151
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 )
167
154
}
168
155
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 < ( ) > {
170
157
let body = serde_json:: to_string ( & OwnersReq { users : owners } ) ?;
171
158
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 ( ( ) )
187
161
}
188
162
189
163
pub fn list_owners ( & mut self , krate : & str ) -> Result < Vec < User > > {
@@ -298,21 +272,8 @@ impl Registry {
298
272
299
273
pub fn unyank ( & mut self , krate : & str , version : & str ) -> Result < ( ) > {
300
274
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 ( ( ) )
316
277
}
317
278
318
279
fn put ( & mut self , path : & str , b : & [ u8 ] ) -> Result < String > {
0 commit comments