mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-27 12:05:26 +00:00
Check errors of more database calls
This commit is contained in:
parent
a1837a4d69
commit
a09633e859
13
api.go
13
api.go
@ -475,7 +475,16 @@ func (h *Headscale) handleMachineRefreshKey(
|
|||||||
Str("machine", machine.Name).
|
Str("machine", machine.Name).
|
||||||
Msg("We have the OldNodeKey in the database. This is a key refresh")
|
Msg("We have the OldNodeKey in the database. This is a key refresh")
|
||||||
machine.NodeKey = NodePublicKeyStripPrefix(registerRequest.NodeKey)
|
machine.NodeKey = NodePublicKeyStripPrefix(registerRequest.NodeKey)
|
||||||
h.db.Save(&machine)
|
|
||||||
|
if err := h.db.Save(&machine).Error; err != nil {
|
||||||
|
log.Error().
|
||||||
|
Caller().
|
||||||
|
Err(err).
|
||||||
|
Msg("Failed to update machine key in the database")
|
||||||
|
ctx.String(http.StatusInternalServerError, "Internal server error")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
resp.AuthURL = ""
|
resp.AuthURL = ""
|
||||||
resp.User = *machine.Namespace.toUser()
|
resp.User = *machine.Namespace.toUser()
|
||||||
@ -485,7 +494,7 @@ func (h *Headscale) handleMachineRefreshKey(
|
|||||||
Caller().
|
Caller().
|
||||||
Err(err).
|
Err(err).
|
||||||
Msg("Cannot encode message")
|
Msg("Cannot encode message")
|
||||||
ctx.String(http.StatusInternalServerError, "Extremely sad!")
|
ctx.String(http.StatusInternalServerError, "Internal server error")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
4
db.go
4
db.go
@ -175,7 +175,9 @@ func (h *Headscale) setValue(key string, value string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h.db.Create(keyValue)
|
if err := h.db.Create(keyValue).Error; err != nil {
|
||||||
|
return fmt.Errorf("failed to create key value pair in the database: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
15
poll.go
15
poll.go
@ -126,7 +126,20 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
|
|||||||
machine.Endpoints = req.Endpoints
|
machine.Endpoints = req.Endpoints
|
||||||
machine.LastSeen = &now
|
machine.LastSeen = &now
|
||||||
}
|
}
|
||||||
h.db.Updates(machine)
|
|
||||||
|
if err := h.db.Updates(machine).Error; err != nil {
|
||||||
|
if err != nil {
|
||||||
|
log.Error().
|
||||||
|
Str("handler", "PollNetMap").
|
||||||
|
Str("id", ctx.Param("id")).
|
||||||
|
Str("machine", machine.Name).
|
||||||
|
Err(err).
|
||||||
|
Msg("Failed to persist/update machine in the database")
|
||||||
|
ctx.String(http.StatusInternalServerError, ":(")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data, err := h.getMapResponse(machineKey, req, machine)
|
data, err := h.getMapResponse(machineKey, req, machine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user