Skip to content

Commit e92c21d

Browse files
committed
chore: add new redactor for telemetry proxy *url.Error types
1 parent 72f2adb commit e92c21d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

api/internal/handler/datalogger_proxy.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"fmt"
99
"io"
1010
"net/http"
11+
"net/url"
1112

1213
"github.com/USACE/instrumentation-api/api/v4/internal/httperr"
1314
"github.com/USACE/instrumentation-api/api/v4/internal/service"
15+
"github.com/USACE/instrumentation-api/api/v4/internal/util"
1416
"github.com/danielgtaylor/huma/v2"
1517
)
1618

@@ -50,7 +52,17 @@ func (h *TelemetryHandler) RegisterDataloggerProxy(api huma.API) {
5052

5153
res, err := h.Client.Do(req)
5254
if err != nil {
53-
return nil, httperr.InternalServerError(err)
55+
var urlErr *url.Error
56+
if errors.As(err, &urlErr) {
57+
u, err := url.Parse(urlErr.URL)
58+
if err != nil {
59+
return nil, httperr.InternalServerError(errors.New("error occured while attempting to parse the url of another error"))
60+
}
61+
util.RedactQueryParams(u, "key")
62+
urlErr.URL = u.String()
63+
return nil, httperr.InternalServerError(urlErr)
64+
}
65+
return nil, httperr.InternalServerError(fmt.Errorf("expected error to be *url.Error type, got %T", err))
5466
}
5567
resBody, err := io.ReadAll(res.Body)
5668
if err != nil {

0 commit comments

Comments
 (0)