@@ -27,6 +27,9 @@ pub enum ApiError {
2727 #[ error( "Not Found" ) ]
2828 NotFound ,
2929
30+ #[ error( "Bad Request" ) ]
31+ BadRequest ( String ) ,
32+
3033 #[ error( "Not Found Workflow: {0}" ) ]
3134 NotFoundWorkflow ( String ) ,
3235
@@ -38,18 +41,38 @@ pub enum ApiError {
3841
3942 #[ error( "Bad Workflow Request: {0}" ) ]
4043 BadWorkflowRequest ( String ) ,
44+
45+ #[ error( "Invalid path" ) ]
46+ InvalidPath ,
47+
48+ #[ error( "Axum error: {0}" ) ]
49+ AxumError ( String ) ,
50+
51+ #[ error( "Git command failed: {0}" ) ]
52+ GitCommandFailed ( String ) ,
53+ }
54+
55+ impl From < axum:: http:: Error > for ApiError {
56+ fn from ( err : axum:: http:: Error ) -> Self {
57+ ApiError :: AxumError ( err. to_string ( ) )
58+ }
4159}
4260
4361impl IntoResponse for ApiError {
4462 fn into_response ( self ) -> axum:: response:: Response {
45- let ( status, message) = match self {
46- Self :: InternalServerError => ( StatusCode :: INTERNAL_SERVER_ERROR , self . to_string ( ) ) ,
47- Self :: NotFound => ( StatusCode :: NOT_FOUND , self . to_string ( ) ) ,
48- Self :: NotFoundWorkflow ( e) => ( StatusCode :: NOT_FOUND , e. to_string ( ) ) ,
49- Self :: FailedToCreateWorkflow ( e) => ( StatusCode :: BAD_REQUEST , e. to_string ( ) ) ,
50- Self :: FailedToDeleteWorkflow ( e) => ( StatusCode :: INTERNAL_SERVER_ERROR , e. to_string ( ) ) ,
51- Self :: BadWorkflowRequest ( e) => ( StatusCode :: BAD_REQUEST , e. to_string ( ) ) ,
63+ let status = match self {
64+ Self :: InternalServerError => StatusCode :: INTERNAL_SERVER_ERROR ,
65+ Self :: NotFound => StatusCode :: NOT_FOUND ,
66+ Self :: BadRequest ( _) => StatusCode :: BAD_REQUEST ,
67+ Self :: NotFoundWorkflow ( _) => StatusCode :: NOT_FOUND ,
68+ Self :: FailedToCreateWorkflow ( _) => StatusCode :: BAD_REQUEST ,
69+ Self :: FailedToDeleteWorkflow ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
70+ Self :: BadWorkflowRequest ( _) => StatusCode :: BAD_REQUEST ,
71+ Self :: InvalidPath => StatusCode :: BAD_REQUEST ,
72+ Self :: AxumError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
73+ Self :: GitCommandFailed ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
5274 } ;
75+ let message = self . to_string ( ) ;
5376
5477 error ! ( "{} - {}" , status, message) ;
5578 ( status, Json ( json ! ( { "message" : message } ) ) ) . into_response ( )
0 commit comments