add descriptive error
This commit is contained in:
parent
8d1d686355
commit
44b2f0ba6e
2 changed files with 19 additions and 4 deletions
15
main.go
15
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() {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue