mirror of https://github.com/fiatjaf/nak.git
optimized clamped error message for status code failures.
This commit is contained in:
parent
5bcf2da794
commit
fc255b5a9a
|
@ -381,9 +381,15 @@ func unwrapAll(err error) error {
|
||||||
func clampMessage(msg string, prefixAlreadyPrinted int) string {
|
func clampMessage(msg string, prefixAlreadyPrinted int) string {
|
||||||
termSize, _, _ := term.GetSize(int(os.Stderr.Fd()))
|
termSize, _, _ := term.GetSize(int(os.Stderr.Fd()))
|
||||||
|
|
||||||
|
prf := "expected handshake response status code 101 but got "
|
||||||
|
if len(msg) > len(prf) && msg[0:len(prf)] == prf {
|
||||||
|
msg = "status " + msg[len(prf):]
|
||||||
|
}
|
||||||
|
|
||||||
if len(msg) > termSize-prefixAlreadyPrinted && prefixAlreadyPrinted+1 < termSize {
|
if len(msg) > termSize-prefixAlreadyPrinted && prefixAlreadyPrinted+1 < termSize {
|
||||||
msg = msg[0:termSize-prefixAlreadyPrinted-1] + "…"
|
msg = msg[0:termSize-prefixAlreadyPrinted-1] + "…"
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue