From cd3a06b76c4edd0b5e84b361cc85a194e57bffab Mon Sep 17 00:00:00 2001 From: Samantha Date: Wed, 28 Oct 2020 21:13:31 -0700 Subject: [PATCH] publisher: replacing error assertions with errors.As (#5147) Part of #5010 --- publisher/publisher.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/publisher/publisher.go b/publisher/publisher.go index c756d56da..0c18302fd 100644 --- a/publisher/publisher.go +++ b/publisher/publisher.go @@ -10,6 +10,7 @@ import ( "encoding/asn1" "encoding/base64" "encoding/json" + "errors" "fmt" "math/big" "net/http" @@ -254,8 +255,9 @@ func (pub *Impl) SubmitToSingleCTWithResult(ctx context.Context, req *pubpb.Requ return nil, err } var body string - if respErr, ok := err.(jsonclient.RspError); ok && respErr.StatusCode < 500 { - body = string(respErr.Body) + var rspErr jsonclient.RspError + if errors.As(err, &rspErr) && rspErr.StatusCode < 500 { + body = string(rspErr.Body) } pub.log.AuditErrf("Failed to submit certificate to CT log at %s: %s Body=%q", ctLog.uri, err, body) @@ -291,7 +293,8 @@ func (pub *Impl) singleLogSubmit( status = "canceled" } httpStatus := "" - if rspError, ok := err.(ctClient.RspError); ok && rspError.StatusCode != 0 { + var rspError ctClient.RspError + if errors.As(err, &rspError) && rspError.StatusCode != 0 { httpStatus = fmt.Sprintf("%d", rspError.StatusCode) } pub.metrics.submissionLatency.With(prometheus.Labels{