@@ -27,6 +27,8 @@ const GITHUB_RELEASE_LATEST: &str = "https://github.com/deepinfra/deepctl/releas
2727
2828#[ derive( Error , Debug ) ]
2929pub enum DeepCtlError {
30+ #[ error( "Error: {0}" ) ]
31+ Error ( String ) ,
3032 #[ error( "You need to log in first" ) ]
3133 NotLoggedIn ( #[ from] anyhow:: Error ) ,
3234 #[ error( "Invalid configuration file" ) ]
@@ -643,7 +645,7 @@ fn infer_out_part(value: &serde_json::Value, location: &str) -> Result<()> {
643645fn infer ( model_name : & str , args : & Vec < ( String , String ) > , outs : & Vec < ( String , String ) > , dev : bool ) -> Result < ( ) > {
644646 let form = infer_body ( args) ?;
645647
646- let json = get_parsed_response_extra (
648+ let response = get_response_extra (
647649 & format ! ( "/v1/inference/{}" , model_name) ,
648650 Method :: POST ,
649651 dev,
@@ -654,6 +656,15 @@ fn infer(model_name: &str, args: &Vec<(String, String)>, outs: &Vec<(String, Str
654656 } ,
655657 ) ?;
656658
659+ if !response. status ( ) . is_success ( ) {
660+ let status = response. status ( ) ;
661+ let error_json: serde_json:: Value = serde_json:: from_str ( & response. text ( ) ?) ?;
662+ let error_str = serde_json:: to_string_pretty ( & error_json) ?;
663+ return Err ( DeepCtlError :: Error ( format ! ( "{}: {}" , status, error_str) ) . into ( ) ) ;
664+ }
665+
666+ let json: serde_json:: Value = serde_json:: from_str ( & response. text ( ) ?) ?;
667+
657668 let outs_default = & vec ! [ ( "" . to_owned( ) , "-" . to_owned( ) ) ] ;
658669 let outs = if outs. len ( ) == 0 { outs_default } else { outs } ;
659670 for ( path, target) in outs {
0 commit comments