• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SwissDataScienceCenter / renku-gateway / 25162847207

30 Apr 2026 11:27AM UTC coverage: 42.531% (-0.5%) from 42.994%
25162847207

Pull #866

gihub-action

olevski
chore: move code to a separate file
Pull Request #866: chore: centralized error formatting

0 of 33 new or added lines in 2 files covered. (0.0%)

1304 of 3066 relevant lines covered (42.53%)

4.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/revproxy/error_handler.go
1
package revproxy
2

3
import (
4
        "errors"
5
        "fmt"
6
        "net/http"
7
        "strings"
8

9
        "github.com/labstack/echo/v4"
10
)
11

12
// The same error content as the data services API
13
const gwBaseErrorCode int = 6000
14

15
type errorContent struct {
16
        Code    int    `json:"code"`
17
        Message string `json:"message"`
18
        Detail  string `json:"detail,omitempty"`
19
        TraceId string `json:"trace_id,omitempty"`
20
}
21

22
type errorResponse struct {
23
        Error errorContent `json:"error"`
24
}
25

26
// Adapted from https://echo.labstack.com/docs/error-handling
NEW
27
func ErrorHandler(err error, c echo.Context) {
×
NEW
28
        if c.Response() != nil && c.Response().Committed {
×
NEW
29
                return // response has been already sent to the client by handler or some middleware
×
NEW
30
        }
×
31

NEW
32
        accept := c.Request().Header.Get("Accept")
×
NEW
33
        isHTML := strings.Contains(accept, echo.MIMETextHTML)
×
NEW
34

×
NEW
35
        // If the accept header is html then we fall back to the default handler (for now).
×
NEW
36
        // If the acceptt header is not html or is blank we return json
×
NEW
37
        if isHTML {
×
NEW
38
                c.Echo().DefaultHTTPErrorHandler(err, c)
×
NEW
39
                return
×
NEW
40
        }
×
41

NEW
42
        code := http.StatusInternalServerError
×
NEW
43
        message := err.Error()
×
NEW
44
        var he *echo.HTTPError
×
NEW
45
        if errors.As(err, &he) { // find error in an error chain that implements HTTPError
×
NEW
46
                if tmp := he.Code; tmp != 0 {
×
NEW
47
                        code = tmp
×
NEW
48
                }
×
NEW
49
                if msg := fmt.Sprintf("%v", he.Message); len(msg) > 0 {
×
NEW
50
                        message = msg
×
NEW
51
                }
×
52
        }
53

NEW
54
        var cErr error
×
NEW
55
        if c.Request().Method == http.MethodHead {
×
NEW
56
                cErr = c.NoContent(code)
×
NEW
57
        } else {
×
NEW
58
                cErr = c.JSON(code, errorResponse{Error: errorContent{Code: gwBaseErrorCode + code, Message: message}})
×
NEW
59
        }
×
NEW
60
        if cErr != nil {
×
NEW
61
                c.Logger().Error("failed to send error page to client", "error", errors.Join(err, cErr))
×
NEW
62
        }
×
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc