From bbb2ac1fc4ff4f0a579212f622852a352be38270 Mon Sep 17 00:00:00 2001 From: mikecohen Date: Mon, 22 Jul 2019 09:16:44 -0700 Subject: [PATCH] Add in a fixed percentage of 500 errors in responses. --- src/frontend/handlers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/frontend/handlers.go b/src/frontend/handlers.go index d7e8765..46d1a6b 100644 --- a/src/frontend/handlers.go +++ b/src/frontend/handlers.go @@ -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