mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-07 21:02:51 -05:00
Return better web errors to the user (#2398)
* add dedicated http error to propagate to user Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> * classify user errors in http handlers Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> * move validation of pre auth key out of db This move separates the logic a bit and allow us to write specific errors for the caller, in this case the web layer so we can present the user with the correct error codes without bleeding web stuff into a generic validate. Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> * update changelog Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> --------- Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
@@ -181,11 +181,15 @@ func (api headscaleV1APIServer) ExpirePreAuthKey(
|
||||
request *v1.ExpirePreAuthKeyRequest,
|
||||
) (*v1.ExpirePreAuthKeyResponse, error) {
|
||||
err := api.h.db.Write(func(tx *gorm.DB) error {
|
||||
preAuthKey, err := db.GetPreAuthKey(tx, request.GetUser(), request.Key)
|
||||
preAuthKey, err := db.GetPreAuthKey(tx, request.Key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if preAuthKey.User.Name != request.GetUser() {
|
||||
return fmt.Errorf("preauth key does not belong to user")
|
||||
}
|
||||
|
||||
return db.ExpirePreAuthKey(tx, preAuthKey)
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user