mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 05:52:20 +08:00
improve conn refused error check
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> rewrite path to filepath in fsrepo License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> remove api file on repo close License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> update function to check normal net.OpErrors License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
@ -671,6 +673,15 @@ func apiClientForAddr(addr ma.Multiaddr) (cmdsHttp.Client, error) {
|
||||
}
|
||||
|
||||
func isConnRefused(err error) bool {
|
||||
return strings.Contains(err.Error(), "connection refused") ||
|
||||
strings.Contains(err.Error(), "target machine actively refused it")
|
||||
// unwrap url errors from http calls
|
||||
if urlerr, ok := err.(*url.Error); ok {
|
||||
err = urlerr.Err
|
||||
}
|
||||
|
||||
netoperr, ok := err.(*net.OpError)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return netoperr.Op == "dial"
|
||||
}
|
||||
|
Reference in New Issue
Block a user