mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
Added HTTP responses on errors
This commit is contained in:
parent
f66c283756
commit
bff3d2d613
5
api.go
5
api.go
@ -188,18 +188,21 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
|
|||||||
mKey, err := wgkey.ParseHex(mKeyStr)
|
mKey, err := wgkey.ParseHex(mKeyStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot parse client key: %s", err)
|
log.Printf("Cannot parse client key: %s", err)
|
||||||
|
c.String(http.StatusBadRequest, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := tailcfg.MapRequest{}
|
req := tailcfg.MapRequest{}
|
||||||
err = decode(body, &req, &mKey, h.privateKey)
|
err = decode(body, &req, &mKey, h.privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot decode message: %s", err)
|
log.Printf("Cannot decode message: %s", err)
|
||||||
|
c.String(http.StatusBadRequest, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var m Machine
|
var m Machine
|
||||||
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
log.Printf("Ignoring request, cannot find machine with key %s", mKey.HexString())
|
log.Printf("Ignoring request, cannot find machine with key %s", mKey.HexString())
|
||||||
|
c.String(http.StatusUnauthorized, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +290,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
|
|||||||
log.Printf("[%s] Sending data (%d bytes)", m.Name, len(data))
|
log.Printf("[%s] Sending data (%d bytes)", m.Name, len(data))
|
||||||
_, err := w.Write(data)
|
_, err := w.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] 🤮 Cannot write data: %s", m.Name, err)
|
log.Printf("[%s] Cannot write data: %s", m.Name, err)
|
||||||
}
|
}
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
m.LastSeen = &now
|
m.LastSeen = &now
|
||||||
|
Loading…
Reference in New Issue
Block a user