1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 "git.arvados.org/arvados.git/sdk/go/arvados"
12 "git.arvados.org/arvados.git/sdk/go/ctxlog"
13 "github.com/sirupsen/logrus"
16 // ErrorHandler returns a Handler that reports itself as unhealthy and
17 // responds 500 to all requests. ErrorHandler itself logs the given
18 // error once, and the handler logs it again for each incoming
20 func ErrorHandler(ctx context.Context, _ *arvados.Cluster, err error) Handler {
21 logger := ctxlog.FromContext(ctx)
22 logger.WithError(err).Error("unhealthy service")
23 return errorHandler{err, logger}
26 type errorHandler struct {
28 logger logrus.FieldLogger
31 func (eh errorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
32 eh.logger.WithError(eh.err).Error("unhealthy service")
33 http.Error(w, "", http.StatusInternalServerError)
36 func (eh errorHandler) CheckHealth() error {