Skip to content

Commit 221e756

Browse files
committed
Use render.Error on crl endpoint
1 parent 0829f37 commit 221e756

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

api/crl.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,31 @@ package api
22

33
import (
44
"encoding/pem"
5-
"fmt"
6-
"github.com/pkg/errors"
7-
"github.com/smallstep/certificates/errs"
85
"net/http"
6+
7+
"github.com/smallstep/certificates/api/render"
98
)
109

1110
// CRL is an HTTP handler that returns the current CRL in DER or PEM format
1211
func CRL(w http.ResponseWriter, r *http.Request) {
1312
crlBytes, err := mustAuthority(r.Context()).GetCertificateRevocationList()
14-
15-
_, formatAsPEM := r.URL.Query()["pem"]
16-
1713
if err != nil {
18-
19-
caErr, isCaErr := err.(*errs.Error)
20-
21-
if isCaErr {
22-
http.Error(w, caErr.Msg, caErr.Status)
23-
return
24-
}
25-
26-
w.WriteHeader(500)
27-
_, err = fmt.Fprintf(w, "%v\n", err)
28-
if err != nil {
29-
panic(errors.Wrap(err, "error writing http response"))
30-
}
14+
render.Error(w, err)
3115
return
3216
}
3317

18+
_, formatAsPEM := r.URL.Query()["pem"]
3419
if formatAsPEM {
3520
pemBytes := pem.EncodeToMemory(&pem.Block{
3621
Type: "X509 CRL",
3722
Bytes: crlBytes,
3823
})
3924
w.Header().Add("Content-Type", "application/x-pem-file")
4025
w.Header().Add("Content-Disposition", "attachment; filename=\"crl.pem\"")
41-
_, err = w.Write(pemBytes)
26+
w.Write(pemBytes)
4227
} else {
4328
w.Header().Add("Content-Type", "application/pkix-crl")
4429
w.Header().Add("Content-Disposition", "attachment; filename=\"crl.der\"")
45-
_, err = w.Write(crlBytes)
46-
}
47-
48-
if err != nil {
49-
panic(errors.Wrap(err, "error writing http response"))
30+
w.Write(crlBytes)
5031
}
51-
5232
}

0 commit comments

Comments
 (0)