@@ -16,7 +16,7 @@ use crate::models::{
1616 ReverseDependency , User , Version ,
1717} ;
1818use crate :: schema:: * ;
19- use crate :: util:: errors:: { bad_request , version_not_found, AppResult } ;
19+ use crate :: util:: errors:: { version_not_found, AppResult } ;
2020use crate :: { app:: App , util:: errors:: BoxedAppError } ;
2121use crates_io_diesel_helpers:: canon_crate_name;
2222
@@ -441,7 +441,11 @@ impl Crate {
441441 }
442442 }
443443
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 > {
445449 let query = diesel:: sql_query (
446450 r#"WITH crate_owners_with_login AS (
447451 SELECT
@@ -477,8 +481,7 @@ impl Crate {
477481 . await ?;
478482
479483 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) ) ;
482485 }
483486
484487 Ok ( ( ) )
@@ -533,6 +536,21 @@ pub enum OwnerAddError {
533536 AlreadyInvited ( Box < User > ) ,
534537}
535538
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+
536554/// A [`BoxedAppError`] does not impl [`std::error::Error`] so it needs a manual
537555/// [`From`] impl.
538556impl From < BoxedAppError > for OwnerAddError {
0 commit comments