Skip to content

Commit 3b36ffa

Browse files
committed
fix user-activity response on no rows
1 parent 4e36a62 commit 3b36ffa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

coderd/insights.go

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coderd
22

33
import (
44
"context"
5+
"database/sql"
56
"fmt"
67
"net/http"
78
"strings"
@@ -102,6 +103,19 @@ func (api *API) insightsUserActivity(rw http.ResponseWriter, r *http.Request) {
102103
TemplateIDs: templateIDs,
103104
})
104105
if err != nil {
106+
// No data is not an error.
107+
if xerrors.Is(err, sql.ErrNoRows) {
108+
httpapi.Write(ctx, rw, http.StatusOK, codersdk.UserActivityInsightsResponse{
109+
Report: codersdk.UserActivityInsightsReport{
110+
StartTime: startTime,
111+
EndTime: endTime,
112+
TemplateIDs: []uuid.UUID{},
113+
Users: []codersdk.UserActivity{},
114+
},
115+
})
116+
return
117+
}
118+
// Check authorization.
105119
if httpapi.Is404Error(err) {
106120
httpapi.ResourceNotFound(rw)
107121
return

0 commit comments

Comments
 (0)