publisher: replacing error assertions with errors.As (#5147)

Part of #5010
This commit is contained in:
Samantha 2020-10-28 21:13:31 -07:00 committed by GitHub
parent 176253addd
commit cd3a06b76c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import (
"encoding/asn1" "encoding/asn1"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"net/http" "net/http"
@ -254,8 +255,9 @@ func (pub *Impl) SubmitToSingleCTWithResult(ctx context.Context, req *pubpb.Requ
return nil, err return nil, err
} }
var body string var body string
if respErr, ok := err.(jsonclient.RspError); ok && respErr.StatusCode < 500 { var rspErr jsonclient.RspError
body = string(respErr.Body) 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", pub.log.AuditErrf("Failed to submit certificate to CT log at %s: %s Body=%q",
ctLog.uri, err, body) ctLog.uri, err, body)
@ -291,7 +293,8 @@ func (pub *Impl) singleLogSubmit(
status = "canceled" status = "canceled"
} }
httpStatus := "" 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) httpStatus = fmt.Sprintf("%d", rspError.StatusCode)
} }
pub.metrics.submissionLatency.With(prometheus.Labels{ pub.metrics.submissionLatency.With(prometheus.Labels{