Is possible to set a fallback for dnf proxy?

On workstation Fedora 39 I have set a proxy by this:
/etc/dnf/dnf.conf

proxy=http://<myurl>:port

All work but if http://<myurl>:port is down, All fail.

I like to setup a fallback beaviour if proxy is not reachable.

How can tell to dnf to ignore proxy setting if proxy fail?
It is possible?

I search by google but haven’t find any solution

best regards,
Leonardo

sudo tee /etc/profile.d/dnf.sh << "EOF" > /dev/null
dnf() {
    local PROXY="domain:port"
    local OPTION
    if ping -q -c 1 -W 3 "${PROXY%:*}" &> /dev/null
    then OPTION="--setopt proxy=http://${PROXY}"
    else OPTION=""
    fi
    sudo dnf ${OPTION} "${@}"
}
EOF
. /etc/profile.d/dnf.sh

thanks @vgaetera Your solution work well but I have do some chenge to let the command work using sudo: typing the command like $ sudo dnf ...

I write file 99% like yuour:
$ sudo vim /usr/local/bin/_dnf
(I add 2 echo command to let me see if the proxy is up)

#!/bin/bash
_dnf() {
    local PROXY="<my-proxy-url:port>"
    local OPTION
    if ping -q -c 1 -W 3 "${PROXY%:*}" &> /dev/null
    then
      OPTION="--setopt proxy=http://${PROXY}"
      echo "proxy==http://${PROXY}"
    else
      OPTION=""
      echo "no proxy"
    fi
    sudo dnf ${OPTION} "${@}"
}
_dnf "${@}"
exit 0

then
$ sudo chmod ugo+x /usr/local/bin/_dnf

then I modify my alias:
$ vim ~/.bashrc.d/0010-aliases.rc

alias sudo='sudo '
alias dnf='_dnf'

The sudo alias need to make alias metch $ sudo command
using this we can use transparent command like
$ sudo dnf info neovim
and all work well.

best regards,
Leonardo

Update

there is a problem if we call $ sudo dnf ${OPTION} "${@}"
some alias not work so I have change the script and add noproxy option in the rare case we won’t to not use the proxy and not disable the alias.

 #!/bin/bash
_dnf() {
    local PROXY="<my-proxy-url:port>"
    local OPTION
    if [ "noproxy" != "$1" ]
    then
      if ping -q -c 1 -W 3 "${PROXY%:*}" &> /dev/null
      then
        OPTION="--setopt proxy=http://${PROXY}"
        echo "proxy==http://${PROXY}"
      else
        OPTION=""
        echo "no proxy"
      fi
      sudo dnf "${@}" ${OPTION} 
    else
      set -- "${@:2}"
      sudo dnf "${@}" ${OPTION} 
    fi
}
_dnf "${@}"
exit 0