Skip to content

Commit

Permalink
fix: handle error in user creation DB call
Browse files Browse the repository at this point in the history
  • Loading branch information
logan-bobo committed Jun 13, 2024
1 parent 3b863aa commit b48a252
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ func (apiCfg *apiConfig) postAPIUsers(w http.ResponseWriter, r *http.Request) {
UpdatedAt: now,
})

if err != nil {
log.Println(err)
respondWithError(w, http.StatusInternalServerError, "could not create user in database")
}

respondWithJSON(w, http.StatusCreated, APIUserResponseNoToken{
ID: user.ID,
Email: user.Email,
Expand Down
4 changes: 1 addition & 3 deletions internal/shortener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
const urlHashPostfix = "Xa1"

func Hash(inputString string, postfixCount int) string {
var hash [16]byte

hash = md5.Sum([]byte(inputString + strings.Repeat(urlHashPostfix, postfixCount)))
hash := md5.Sum([]byte(inputString + strings.Repeat(urlHashPostfix, postfixCount)))

return hex.EncodeToString(hash[:])
}
Expand Down

0 comments on commit b48a252

Please sign in to comment.