1
0
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:
Jeromy
2015-11-08 11:14:57 -08:00
parent 0b3e0373d5
commit a23609fc4d
2 changed files with 34 additions and 15 deletions

View File

@ -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"
}