9func AsTLSAlert(err error) (alert uint8, ok bool) {
10 // If the remote client aborts the connection, it can send an alert indicating why.
11 // crypto/tls gives us a net.OpError with "Op" set to "remote error", an an Err
12 // with the unexported type "alert", a uint8. So we try to read it.
14 var opErr *net.OpError
15 if !errors.As(err, &opErr) || opErr.Op != "remote error" || opErr.Err == nil {
18 v := reflect.ValueOf(opErr.Err)
19 if v.Kind() != reflect.Uint8 || v.Type().Name() != "alert" {
22 return uint8(v.Uint()), true