Skip to content

Commit dc9ccea

Browse files
committed
Try setting projects outside - is it possible sqlc is returning nil,nil?
1 parent 886d647 commit dc9ccea

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

coderd/projects.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ func (api *api) projects(rw http.ResponseWriter, r *http.Request) {
4242
projects, err := api.Database.GetProjectsByOrganizationIDs(r.Context(), organizationIDs)
4343
if errors.Is(err, sql.ErrNoRows) {
4444
err = nil
45-
projects = []database.Project{}
4645
}
4746
if err != nil {
4847
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
4948
Message: fmt.Sprintf("get projects: %s", err.Error()),
5049
})
5150
return
5251
}
52+
// Don't return 'null'
53+
if projects == nil {
54+
projects = []database.Project{}
55+
}
5356
render.Status(r, http.StatusOK)
5457
render.JSON(rw, r, projects)
5558
}
@@ -60,14 +63,17 @@ func (api *api) projectsByOrganization(rw http.ResponseWriter, r *http.Request)
6063
projects, err := api.Database.GetProjectsByOrganizationIDs(r.Context(), []string{organization.ID})
6164
if errors.Is(err, sql.ErrNoRows) {
6265
err = nil
63-
projects = []database.Project{}
6466
}
6567
if err != nil {
6668
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
6769
Message: fmt.Sprintf("get projects: %s", err.Error()),
6870
})
6971
return
7072
}
73+
// Don't return 'null'
74+
if projects == nil {
75+
projects = []database.Project{}
76+
}
7177
render.Status(r, http.StatusOK)
7278
render.JSON(rw, r, projects)
7379
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy