Add in a fixed percentage of 500 errors in responses.

This commit is contained in:
mikecohen 2019-07-22 09:16:44 -07:00
parent acd728efcf
commit bbb2ac1fc4

View file

@ -43,6 +43,13 @@ func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) {
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
log.WithField("currency", currentCurrency(r)).Info("home")
currencies, err := fe.getCurrencies(r.Context())
// NOTE: This artificially injects failures in a fixed percentage of the responess
if (rand.Intn(100) < 3) {
renderHTTPError(log, r, w, errors.Wrap(err, "Random artificial 500 error"), http.StatusInternalServerError)
return
}
if err != nil {
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
return