@@ -16,7 +16,7 @@ use crate::models::{
16
16
ReverseDependency , User , Version ,
17
17
} ;
18
18
use crate :: schema:: * ;
19
- use crate :: util:: errors:: { bad_request , version_not_found, AppResult } ;
19
+ use crate :: util:: errors:: { version_not_found, AppResult } ;
20
20
use crate :: { app:: App , util:: errors:: BoxedAppError } ;
21
21
use crates_io_diesel_helpers:: canon_crate_name;
22
22
@@ -441,7 +441,11 @@ impl Crate {
441
441
}
442
442
}
443
443
444
- pub async fn owner_remove ( & self , conn : & mut AsyncPgConnection , login : & str ) -> AppResult < ( ) > {
444
+ pub async fn owner_remove (
445
+ & self ,
446
+ conn : & mut AsyncPgConnection ,
447
+ login : & str ,
448
+ ) -> Result < ( ) , OwnerRemoveError > {
445
449
let query = diesel:: sql_query (
446
450
r#"WITH crate_owners_with_login AS (
447
451
SELECT
@@ -477,8 +481,7 @@ impl Crate {
477
481
. await ?;
478
482
479
483
if num_updated_rows == 0 {
480
- let error = format ! ( "could not find owner with login `{login}`" ) ;
481
- return Err ( bad_request ( error) ) ;
484
+ return Err ( OwnerRemoveError :: not_found ( login) ) ;
482
485
}
483
486
484
487
Ok ( ( ) )
@@ -533,6 +536,21 @@ pub enum OwnerAddError {
533
536
AlreadyInvited ( Box < User > ) ,
534
537
}
535
538
539
+ #[ derive( Debug , Error ) ]
540
+ pub enum OwnerRemoveError {
541
+ #[ error( transparent) ]
542
+ Diesel ( #[ from] diesel:: result:: Error ) ,
543
+ #[ error( "Could not find owner with login `{login}`" ) ]
544
+ NotFound { login : String } ,
545
+ }
546
+
547
+ impl OwnerRemoveError {
548
+ pub fn not_found ( login : & str ) -> Self {
549
+ let login = login. to_string ( ) ;
550
+ Self :: NotFound { login }
551
+ }
552
+ }
553
+
536
554
/// A [`BoxedAppError`] does not impl [`std::error::Error`] so it needs a manual
537
555
/// [`From`] impl.
538
556
impl From < BoxedAppError > for OwnerAddError {
0 commit comments