Skip to content

Commit 355f163

Browse files
committed
Return hash error as server error
1 parent 2699445 commit 355f163

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

coderd/users.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ func (api *api) putUserSuspend(rw http.ResponseWriter, r *http.Request) {
360360
httpapi.Write(rw, http.StatusOK, convertUser(suspendedUser, organizations))
361361
}
362362

363-
func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) error {
363+
func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) {
364364
user := httpmw.UserParam(r)
365365

366366
var params codersdk.UpdateUserPasswordRequest
367367
if !httpapi.Read(rw, r, &params) {
368-
return nil
368+
return
369369
}
370370

371371
// Check if the new password and the confirmation match
@@ -380,13 +380,15 @@ func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) error {
380380
Message: fmt.Sprintf("The new password and the new password confirmation don't match"),
381381
Errors: requestErrors,
382382
})
383-
return nil
383+
return
384384
}
385385

386386
// Hash password and update it in the database
387387
hashedPassword, hashError := userpassword.Hash(params.NewPassword)
388388
if hashError != nil {
389-
return xerrors.Errorf("hash password: %w", hashError)
389+
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
390+
Message: fmt.Sprintf("hash password: %s", hashError.Error()),
391+
})
390392
}
391393
databaseError := api.Database.UpdateUserHashedPassword(r.Context(), database.UpdateUserHashedPasswordParams{
392394
ID: user.ID,
@@ -396,11 +398,10 @@ func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) error {
396398
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
397399
Message: fmt.Sprintf("put user password: %s", databaseError.Error()),
398400
})
399-
return nil
401+
return
400402
}
401403

402404
httpapi.Write(rw, http.StatusNoContent, nil)
403-
return nil
404405
}
405406

406407
func (api *api) userRoles(rw http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)