TLS dial error pkg variables - Best way to logically detect the type of tls failure

75 vues
Accéder directement au premier message non lu

Kevin Chadwick

non lue,
2 juin 2020, 11:22:3402/06/2020
à golang-nuts
I want my client application to behave differently depending upon whether the
server is down or it is a "x509: certificate signed by unknown authority" condition.

It seems there isn't an errors.Is (btw the dot syntax makes it difficult to
google search!)

I intend to just string match the returned error. However, as it isn't a pkg
variable (had to grep). Does the string fall outside the compatibility promise?

If so. Is there a better way or should I just create a test to run on every
stdlib upgrade?

Thanks

Matt Harden

non lue,
7 juin 2020, 21:50:1907/06/2020
à Kevin Chadwick,golang-nuts
I suspect your (possibly wrapped) error will be of type x509.UnknownAuthorityError, so you should be able to check for it with errors.As:

var uaerr x509.UnknownAuthorityError
if errors.As(err, &uaerr) {
  // handle as an unknown authority error
}

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f4ddc813-ade5-7501-4fb4-d19dba375a4f%40gmail.com.

Kevin Chadwick

non lue,
8 juin 2020, 06:35:4008/06/2020
à golan...@googlegroups.com
On 2020-06-08 01:49, Matt Harden wrote:
> I suspect your (possibly wrapped) error will be of type
> x509.UnknownAuthorityError, so you should be able to check for it with errors.As:
>
> var uaerr x509.UnknownAuthorityError
> if errors.As(err, &uaerr) {
>   // handle as an unknown authority error
> }

Thank You

It is even documented at the bottom of the x509 doc!

I read errors could be found in "Variables", in a forum and assumed they would
all be in one place, doh.

I guess a case sensitive search for Error, may work.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message