File tree Expand file tree Collapse file tree
src/bourso_api/src/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -567,22 +567,20 @@ fn extract_token(res: &str) -> Result<String> {
567567/// # Returns
568568/// A tuple containing the resource ID and form state as strings.
569569fn extract_otp_params ( res : & str ) -> Result < ( String , String ) > {
570- let captures = OTP_PARAMS_REGEX . captures ( & res) ;
571-
572- let challenge_json = if let Some ( captures) = captures {
573- let challenge_str = captures. get ( 1 )
574- . map ( |m| m. as_str ( ) )
575- . ok_or_else ( || {
576- error ! ( "{}" , res) ;
577- anyhow:: anyhow!( "Could not extract authentication challenge from regex match" )
578- } ) ?;
579- // HTML decode the JSON string (replace " with ")
580- let decoded = challenge_str. replace ( """ , "\" " ) ;
581- serde_json:: from_str :: < serde_json:: Value > ( & decoded) ?
582- } else {
583- error ! ( "{}" , res) ;
584- bail ! ( "Could not extract authentication challenge parameters" ) ;
585- } ;
570+ let challenge_json = OTP_PARAMS_REGEX
571+ . captures ( & res)
572+ . and_then ( |c| c. get ( 1 ) )
573+ . map ( |m| m. as_str ( ) )
574+ . ok_or_else ( || {
575+ error ! ( "{}" , res) ;
576+ anyhow:: anyhow!( "Could not extract authentication challenge parameters" )
577+ } )
578+ . and_then ( |challenge_str| {
579+ // HTML decode the JSON string (replace " with ")
580+ let decoded = challenge_str. replace ( """ , "\" " ) ;
581+ serde_json:: from_str :: < serde_json:: Value > ( & decoded)
582+ . map_err ( |e| anyhow:: anyhow!( "Could not parse authentication challenge JSON: {}" , e) )
583+ } ) ?;
586584
587585 Ok ( (
588586 challenge_json[ "challenges" ] [ 0 ] [ "parameters" ] [ "formScreen" ] [ "actions" ] [ "check" ] [ "api" ]
You can’t perform that action at this time.
0 commit comments