taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit 622ec7719b6c0d15d1d649ccf2b14d8166bf155f
parent 3c06d1e8f899855627abedec82526058b226da55
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Fri, 19 Dec 2025 22:00:48 +0900

cleanup: use http status code enum

Diffstat:
Mpkg/taldir/taldir.go | 32++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/pkg/taldir/taldir.go b/pkg/taldir/taldir.go @@ -366,7 +366,7 @@ func (t *Taldir) validationRequest(w http.ResponseWriter, r *http.Request) { var confirm ValidationConfirmation var errDetail ErrorDetail if r.Body == nil { - http.Error(w, "No request body", 400) + http.Error(w, "No request body", http.StatusBadRequest) return } err := json.NewDecoder(r.Body).Decode(&confirm) @@ -374,7 +374,7 @@ func (t *Taldir) validationRequest(w http.ResponseWriter, r *http.Request) { errDetail.Code = 1006 //TALER_EC_JSON_INVALID errDetail.Hint = "Unable to parse JSON" resp, _ := json.Marshal(errDetail) - w.WriteHeader(400) + w.WriteHeader(http.StatusBadRequest) w.Write(resp) return } @@ -386,7 +386,7 @@ func (t *Taldir) validationRequest(w http.ResponseWriter, r *http.Request) { validation.SolutionAttemptCount++ if validation.LastSolutionTimeframeStart.Add(t.SolutionTimeframe).After(time.Now()) { if validation.SolutionAttemptCount > t.SolutionAttemptsMax { - w.WriteHeader(429) + w.WriteHeader(http.StatusTooManyRequests) return } } else { @@ -470,7 +470,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { return } if r.Body == nil { - http.Error(w, "No request body", 400) + http.Error(w, "No request body", http.StatusBadRequest) return } err := json.NewDecoder(r.Body).Decode(&req) @@ -478,7 +478,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { errDetail.Code = gana.GENERIC_JSON_INVALID errDetail.Hint = "Unable to parse JSON" resp, _ := json.Marshal(errDetail) - w.WriteHeader(400) + w.WriteHeader(http.StatusBadRequest) w.Write(resp) return } @@ -490,7 +490,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { errDetail.Hint = err.Error() w.Header().Set("Content-Type", "application/json") resp, _ := json.Marshal(errDetail) - w.WriteHeader(400) + w.WriteHeader(http.StatusBadRequest) w.Write(resp) return } @@ -593,7 +593,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { err = t.DB.Save(&validation).Error if err != nil { t.Logger.Logf(LogError, "%s\n", err.Error()) - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } topic := t.I18n.GetLocale(r).GetMessage("taldirRegTopic") @@ -603,7 +603,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { if err != nil { t.Logger.Logf(LogError, "%s\n", err.Error()) t.DB.Delete(&validation) - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } // FIXME does this persist this boolean or do we need to call Db.Save again? @@ -613,7 +613,7 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, redirectionLink, http.StatusSeeOther) return } - w.WriteHeader(202) + w.WriteHeader(http.StatusAccepted) } func (t *Taldir) oidcValidatorResponse(w http.ResponseWriter, r *http.Request) { @@ -629,7 +629,7 @@ func (t *Taldir) oidcValidatorResponse(w http.ResponseWriter, r *http.Request) { hAlias, challenge, err := oidcValidator.ProcessOidcCallback(r) if err != nil { t.Logger.Logf(LogError, "%s\n", err.Error()) - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } http.Redirect(w, r, fmt.Sprintf("/register/%s/%s", hAlias, challenge), http.StatusSeeOther) @@ -670,19 +670,19 @@ func (t *Taldir) validationPage(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") if err != nil { // This validation does not exist. - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) return } if vars["challenge"] != validation.Challenge { t.Logger.Logf(LogWarning, "Solution does not match challenge!\n") - w.WriteHeader(400) + w.WriteHeader(http.StatusBadRequest) return } alias = r.URL.Query().Get("alias") if alias == "" { - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) return } @@ -692,7 +692,7 @@ func (t *Taldir) validationPage(w http.ResponseWriter, r *http.Request) { if expectedHAlias != validation.HAlias { t.Logger.Logf(LogWarning, "Alias does not match challenge!\n") - w.WriteHeader(400) + w.WriteHeader(http.StatusBadRequest) return } @@ -702,7 +702,7 @@ func (t *Taldir) validationPage(w http.ResponseWriter, r *http.Request) { walletLink = "taler://taldir/" + vars["h_alias"] + "/" + vars["challenge"] + "-wallet" png, err = qrcode.Encode(walletLink, qrcode.Medium, 256) if err != nil { - w.WriteHeader(500) + w.WriteHeader(http.StatusInternalServerError) return } encodedPng := base64.StdEncoding.EncodeToString(png) @@ -891,7 +891,7 @@ func (t *Taldir) typeLandingPage(w http.ResponseWriter, r *http.Request) { // Check if this alias type is supported or not. val, ok := t.Validators[vars["alias_type"]] if !ok { - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) return } fullData := map[string]any{