@@ -166,8 +166,8 @@ func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Requ
166
166
workspaceName := chi .URLParam (r , "workspacename" )
167
167
buildNumber , err := strconv .ParseInt (chi .URLParam (r , "buildnumber" ), 10 , 32 )
168
168
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." ,
171
171
Detail : err .Error (),
172
172
})
173
173
return
@@ -177,14 +177,20 @@ func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Requ
177
177
OwnerID : owner .ID ,
178
178
Name : workspaceName ,
179
179
})
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
+ }
181
186
if err != nil {
182
187
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
183
188
Message : "Internal error fetching workspace by name." ,
184
189
Detail : err .Error (),
185
190
})
186
191
return
187
192
}
193
+
188
194
if ! api .Authorize (rw , r , rbac .ActionRead , rbac .ResourceWorkspace .
189
195
InOrg (workspace .OrganizationID ).WithOwner (workspace .OwnerID .String ()).WithID (workspace .ID .String ())) {
190
196
return
@@ -194,6 +200,12 @@ func (api *API) workspaceBuildByBuildNumber(rw http.ResponseWriter, r *http.Requ
194
200
WorkspaceID : workspace .ID ,
195
201
BuildNumber : int32 (buildNumber ),
196
202
})
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
+ }
197
209
if err != nil {
198
210
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
199
211
Message : "Internal error fetching workspace build." ,
0 commit comments