diff --git a/main.go b/main.go index a7ab615..ac49094 100644 --- a/main.go +++ b/main.go @@ -7,10 +7,17 @@ import ( ) func write_error(w http.ResponseWriter) { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - jsonData := []byte(`{"status":"ERROR","reason":"bad request"}`) - w.Write(jsonData) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + jsonData := []byte(`{"status":"ERROR","reason":"bad request"}`) + w.Write(jsonData) +} + +func write_error_message(w http.ResponseWriter, message string) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + jsonData := []byte(`{"status":"ERROR","reason":"` + message + `"}`) + w.Write(jsonData) } func main() { diff --git a/new_card_request.go b/new_card_request.go index 4a619c9..ec11b01 100644 --- a/new_card_request.go +++ b/new_card_request.go @@ -1,6 +1,7 @@ package main import ( + "database/sql" "encoding/json" log "github.com/sirupsen/logrus" "net/http" @@ -55,6 +56,13 @@ func new_card_request(w http.ResponseWriter, req *http.Request) { lnurlw_base := "lnurlw://" + host_domain + "/ln" c, err := db_get_new_card(a) + + if err == sql.ErrNoRows { + log.Debug(err) + write_error_message(w, "one time code was used or does not exist") + return + } + if err != nil { log.Warn(err) write_error(w)