From b48a252ab21dea5f123efd125a5134b1dc62c9e7 Mon Sep 17 00:00:00 2001 From: Logan Cox Date: Thu, 13 Jun 2024 08:24:17 +0100 Subject: [PATCH] fix: handle error in user creation DB call --- handlers.go | 5 +++++ internal/shortener/main.go | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/handlers.go b/handlers.go index 28a20fd..51e7c45 100644 --- a/handlers.go +++ b/handlers.go @@ -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, diff --git a/internal/shortener/main.go b/internal/shortener/main.go index 456cca5..92e23cf 100644 --- a/internal/shortener/main.go +++ b/internal/shortener/main.go @@ -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[:]) }