Skip to content

Commit 318224c

Browse files
committed
update errors thrown from the API
1 parent d7451d0 commit 318224c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

coderd/workspacebuilds.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Requ
166166
workspaceName := chi.URLParam(r, "workspacename")
167167
buildNumber, err := strconv.ParseInt(chi.URLParam(r, "buildnumber"), 10, 32)
168168
if err != nil {
169-
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
170-
Message: "Internal error parsing build number as integer.",
169+
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
170+
Message: "Failed to parse build number as integer.",
171171
Detail: err.Error(),
172172
})
173173
return
@@ -177,14 +177,20 @@ func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Requ
177177
OwnerID: owner.ID,
178178
Name: workspaceName,
179179
})
180-
180+
if errors.Is(err, sql.ErrNoRows) {
181+
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{
182+
Message: fmt.Sprintf("Workspace %q does not exist.", workspaceName),
183+
})
184+
return
185+
}
181186
if err != nil {
182187
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
183188
Message: "Internal error fetching workspace by name.",
184189
Detail: err.Error(),
185190
})
186191
return
187192
}
193+
188194
if !api.Authorize(rw, r, rbac.ActionRead, rbac.ResourceWorkspace.
189195
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
190196
return
@@ -194,6 +200,12 @@ func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Requ
194200
WorkspaceID: workspace.ID,
195201
BuildNumber: int32(buildNumber),
196202
})
203+
if errors.Is(err, sql.ErrNoRows) {
204+
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{
205+
Message: fmt.Sprintf("Workspace %q Build %q does not exist.", workspaceName, buildNumber),
206+
})
207+
return
208+
}
197209
if err != nil {
198210
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
199211
Message: "Internal error fetching workspace build.",

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