11// use std::fmt::Display;
22
3- use axum:: { extract:: multipart:: MultipartError , http:: StatusCode , response:: IntoResponse , Json } ;
3+ use axum:: {
4+ extract:: multipart:: MultipartError ,
5+ http:: { uri:: InvalidUri , StatusCode } ,
6+ response:: IntoResponse ,
7+ Json ,
8+ } ;
49use blake3:: HexError ;
510use redb:: { CommitError , DatabaseError , StorageError , TableError , TransactionError } ;
611use serde:: { Deserialize , Serialize } ;
@@ -21,6 +26,8 @@ pub enum UsubaError {
2126 InvalidModule ( String ) ,
2227 #[ error( "Module not found" ) ]
2328 ModuleNotFound ,
29+ #[ error( "Upstream request failed: {0}" ) ]
30+ UpstreamError ( String ) ,
2431 #[ error( "An internal error occurred" ) ]
2532 Internal ( String ) ,
2633}
@@ -100,7 +107,20 @@ impl From<JoinError> for UsubaError {
100107
101108impl From < anyhow:: Error > for UsubaError {
102109 fn from ( value : anyhow:: Error ) -> Self {
103- todo ! ( )
110+ UsubaError :: Internal ( format ! ( "{}" , value) )
111+ }
112+ }
113+
114+ impl From < hyper_util:: client:: legacy:: Error > for UsubaError {
115+ fn from ( value : hyper_util:: client:: legacy:: Error ) -> Self {
116+ UsubaError :: UpstreamError ( format ! ( "{}" , value) )
117+ }
118+ }
119+
120+ impl From < InvalidUri > for UsubaError {
121+ fn from ( value : InvalidUri ) -> Self {
122+ warn ! ( "{}" , value) ;
123+ UsubaError :: BadRequest
104124 }
105125}
106126
@@ -113,6 +133,7 @@ impl IntoResponse for UsubaError {
113133 UsubaError :: InvalidConfiguration ( _) => StatusCode :: BAD_REQUEST ,
114134 UsubaError :: Internal ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
115135 UsubaError :: ModuleNotFound => StatusCode :: NOT_FOUND ,
136+ UsubaError :: UpstreamError ( _) => StatusCode :: BAD_GATEWAY ,
116137 } ;
117138
118139 (
0 commit comments