Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: appengine/logdog/coordinator/backend/util.go

Issue 1910633006: LogDog: Support per-namespace expired archival. (Closed) Base URL: https://github.com/luci/luci-go@logdog-coordinator-svcdec
Patch Set: Update another test. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package backend
6
7 import (
8 "fmt"
9 "net/http"
10
11 log "github.com/luci/luci-go/common/logging"
12 "golang.org/x/net/context"
13 )
14
15 // httpError
16 type httpError struct {
17 reason error
18 code int
19 }
20
21 func (e *httpError) Error() string {
22 if r := e.reason; r != nil {
23 return fmt.Sprintf("%v: %q", e.reason, http.StatusText(e.code))
24 }
25 return http.StatusText(e.code)
26 }
27
28 func newHTTPError(reason error, code int) error {
29 return &httpError{reason, code}
30 }
31
32 // errorWrapper wraps an error-returning function and responds with an
33 // InternalServerError if an error is returned.
34 func errorWrapper(c context.Context, w http.ResponseWriter, f func() error) {
35 if err := f(); err != nil {
36 statusCode := http.StatusInternalServerError
37 if e, ok := err.(*httpError); ok {
38 statusCode = e.code
39 }
40
41 log.Fields{
42 log.ErrorKey: err,
43 "statusCode": statusCode,
44 }.Errorf(c, "Backend handler returned error.")
45 w.WriteHeader(statusCode)
46 }
47 }
OLDNEW
« no previous file with comments | « appengine/logdog/coordinator/backend/doc.go ('k') | appengine/logdog/coordinator/backend/util_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698