2020-11-02 00:53:08 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2021-03-29 19:57:13 +00:00
|
|
|
// TimeoutHandler recovers from an http timeout or panic.
|
2020-11-02 00:53:08 +00:00
|
|
|
type TimeoutHandler func()
|
|
|
|
|
|
|
|
// NewTimeoutHandler returns a new Timeout handler.
|
|
|
|
func NewTimeoutHandler(name, addr string, noFail bool) TimeoutHandler {
|
|
|
|
return func() {
|
2020-11-02 23:20:06 +00:00
|
|
|
if r := recover(); r != nil {
|
2021-06-11 22:14:16 +00:00
|
|
|
out := fmt.Sprintf("Failed to authenticate with %s @ \"%s\": Timed out", name, addr)
|
2020-11-02 23:20:06 +00:00
|
|
|
if noFail {
|
|
|
|
log.Print(out)
|
|
|
|
} else {
|
|
|
|
log.Fatalf(out)
|
|
|
|
}
|
2020-11-02 00:53:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|