Fix display of errors (%w is only for Errorf)

This commit is contained in:
nemunaire 2021-07-30 11:49:11 +02:00
parent 89a9c736ae
commit 4f375162a3
16 changed files with 103 additions and 103 deletions

View File

@ -70,13 +70,13 @@ func getAllDomains(c *gin.Context) {
users, err := storage.MainStore.GetUsers() users, err := storage.MainStore.GetUsers()
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to retrieve users list: %w", err)}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to retrieve users list: %s", err.Error())})
return return
} }
for _, user := range users { for _, user := range users {
usersDomains, err := storage.MainStore.GetDomains(user) usersDomains, err := storage.MainStore.GetDomains(user)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to retrieve %s's domains: %w", user.Email, err)}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to retrieve %s's domains: %s", user.Email, err.Error())})
return return
} }
@ -92,7 +92,7 @@ func newDomain(c *gin.Context) {
ud := &happydns.Domain{} ud := &happydns.Domain{}
err := c.ShouldBindJSON(&ud) err := c.ShouldBindJSON(&ud)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
ud.Id = 0 ud.Id = 0
@ -107,7 +107,7 @@ func updateUserDomain(c *gin.Context) {
ud := &happydns.Domain{} ud := &happydns.Domain{}
err := c.ShouldBindJSON(&ud) err := c.ShouldBindJSON(&ud)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
ud.Id = domain.Id ud.Id = domain.Id

View File

@ -98,7 +98,7 @@ func newUserProvider(c *gin.Context) {
us, _, err := api.DecodeProvider(c) us, _, err := api.DecodeProvider(c)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
us.Id = 0 us.Id = 0

View File

@ -103,7 +103,7 @@ func newUser(c *gin.Context) {
uu := &happydns.User{} uu := &happydns.User{}
err := c.ShouldBindJSON(&uu) err := c.ShouldBindJSON(&uu)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
uu.Id = 0 uu.Id = 0
@ -127,7 +127,7 @@ func updateUser(c *gin.Context) {
uu := &happydns.User{} uu := &happydns.User{}
err := c.ShouldBindJSON(&uu) err := c.ShouldBindJSON(&uu)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
uu.Id = user.Id uu.Id = user.Id
@ -163,7 +163,7 @@ func resetUserPasswd(c *gin.Context) {
urp := &resetPassword{} urp := &resetPassword{}
err := c.ShouldBindJSON(&urp) err := c.ShouldBindJSON(&urp)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }

View File

@ -74,7 +74,7 @@ func updateUserDomainZones(c *gin.Context) {
err := c.ShouldBindJSON(&domain.ZoneHistory) err := c.ShouldBindJSON(&domain.ZoneHistory)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -85,7 +85,7 @@ func newUserDomainZone(c *gin.Context) {
uz := &happydns.Zone{} uz := &happydns.Zone{}
err := c.ShouldBindJSON(&uz) err := c.ShouldBindJSON(&uz)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
uz.Id = 0 uz.Id = 0
@ -99,7 +99,7 @@ func updateZone(c *gin.Context) {
uz := &happydns.Zone{} uz := &happydns.Zone{}
err := c.ShouldBindJSON(&uz) err := c.ShouldBindJSON(&uz)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
uz.Id = zone.Id uz.Id = zone.Id
@ -134,7 +134,7 @@ func updateZoneService(c *gin.Context) {
usc := &happydns.ServiceCombined{} usc := &happydns.ServiceCombined{}
err = c.ShouldBindJSON(&usc) err = c.ShouldBindJSON(&usc)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -154,7 +154,7 @@ func patchZoneService(c *gin.Context) {
usc := &happydns.ServiceCombined{} usc := &happydns.ServiceCombined{}
err := c.ShouldBindJSON(&usc) err := c.ShouldBindJSON(&usc)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }

View File

@ -54,12 +54,12 @@ func authMiddleware(opts *config.Options, optional bool) gin.HandlerFunc {
if cookie, err := c.Cookie(COOKIE_NAME); err == nil { if cookie, err := c.Cookie(COOKIE_NAME); err == nil {
if sessionid, err = base64.StdEncoding.DecodeString(cookie); err != nil { if sessionid, err = base64.StdEncoding.DecodeString(cookie); err != nil {
c.SetCookie(COOKIE_NAME, "", -1, opts.BaseURL+"/", "", opts.DevProxy == "", true) c.SetCookie(COOKIE_NAME, "", -1, opts.BaseURL+"/", "", opts.DevProxy == "", true)
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Unable to authenticate request due to invalid cookie value: %w", err)}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Unable to authenticate request due to invalid cookie value: %s", err.Error())})
return return
} }
} else if flds := strings.Fields(c.GetHeader("Authorization")); len(flds) == 2 && flds[0] == "Bearer" { } else if flds := strings.Fields(c.GetHeader("Authorization")); len(flds) == 2 && flds[0] == "Bearer" {
if sessionid, err = base64.StdEncoding.DecodeString(flds[1]); err != nil { if sessionid, err = base64.StdEncoding.DecodeString(flds[1]); err != nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Unable to authenticate request due to invalid Authorization header value: %w", err)}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Unable to authenticate request due to invalid Authorization header value: %s", err.Error())})
return return
} }
} }
@ -72,7 +72,7 @@ func authMiddleware(opts *config.Options, optional bool) gin.HandlerFunc {
session, err := storage.MainStore.GetSession(sessionid) session, err := storage.MainStore.GetSession(sessionid)
if err != nil { if err != nil {
log.Printf("%s tries an invalid session: %w", c.ClientIP(), err) log.Printf("%s tries an invalid session: %s", c.ClientIP(), err.Error())
c.SetCookie(COOKIE_NAME, "", -1, opts.BaseURL+"/", "", opts.DevProxy == "", true) c.SetCookie(COOKIE_NAME, "", -1, opts.BaseURL+"/", "", opts.DevProxy == "", true)
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Your session has expired. Please reconnect.")}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Your session has expired. Please reconnect.")})
return return
@ -82,7 +82,7 @@ func authMiddleware(opts *config.Options, optional bool) gin.HandlerFunc {
user, err := storage.MainStore.GetUser(session.IdUser) user, err := storage.MainStore.GetUser(session.IdUser)
if err != nil { if err != nil {
log.Printf("%s has a correct session, but related user is invalid: %w", c.ClientIP(), err) log.Printf("%s has a correct session, but related user is invalid: %s", c.ClientIP(), err.Error())
c.SetCookie(COOKIE_NAME, "", -1, opts.BaseURL+"/", "", opts.DevProxy == "", true) c.SetCookie(COOKIE_NAME, "", -1, opts.BaseURL+"/", "", opts.DevProxy == "", true)
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Something goes wrong with your session. Please reconnect.")}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Something goes wrong with your session. Please reconnect.")})
return return

View File

@ -65,7 +65,7 @@ func GetDomains(c *gin.Context) {
} }
if domains, err := storage.MainStore.GetDomains(user); err != nil { if domains, err := storage.MainStore.GetDomains(user); err != nil {
log.Printf("%s: An error occurs when trying to GetDomains: %w", c.ClientIP(), err) log.Printf("%s: An error occurs when trying to GetDomains: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": err}) c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": err})
} else if len(domains) > 0 { } else if len(domains) > 0 {
c.JSON(http.StatusOK, domains) c.JSON(http.StatusOK, domains)
@ -78,8 +78,8 @@ func addDomain(c *gin.Context) {
var uz happydns.Domain var uz happydns.Domain
err := c.ShouldBindJSON(&uz) err := c.ShouldBindJSON(&uz)
if err != nil { if err != nil {
log.Printf("%s sends invalid Domain JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid Domain JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -111,7 +111,7 @@ func addDomain(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
return return
} else if err := storage.MainStore.CreateDomain(user, &uz); err != nil { } else if err := storage.MainStore.CreateDomain(user, &uz); err != nil {
log.Printf("%s was unable to CreateDomain: %w", c.ClientIP(), err) log.Printf("%s was unable to CreateDomain: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your domain now."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your domain now."})
return return
} else { } else {
@ -172,7 +172,7 @@ func GetDomain(c *gin.Context) {
zoneMeta, err := storage.MainStore.GetZoneMeta(zm) zoneMeta, err := storage.MainStore.GetZoneMeta(zm)
if err != nil { if err != nil {
log.Println("%s: An error occurs in getDomain, when retrieving a meta history: %w", c.ClientIP(), err) log.Println("%s: An error occurs in getDomain, when retrieving a meta history: %s", c.ClientIP(), err.Error())
} else { } else {
ret.ZoneHistory = append(ret.ZoneHistory, *zoneMeta) ret.ZoneHistory = append(ret.ZoneHistory, *zoneMeta)
} }
@ -183,7 +183,7 @@ func GetDomain(c *gin.Context) {
func delDomain(c *gin.Context) { func delDomain(c *gin.Context) {
if err := storage.MainStore.DeleteDomain(c.MustGet("domain").(*happydns.Domain)); err != nil { if err := storage.MainStore.DeleteDomain(c.MustGet("domain").(*happydns.Domain)); err != nil {
log.Printf("%s was unable to DeleteDomain: %w", c.ClientIP(), err) log.Printf("%s was unable to DeleteDomain: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to delete your domain: %s", err.Error())}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to delete your domain: %s", err.Error())})
return return
} }

View File

@ -73,7 +73,7 @@ func getProviderSettingsState(cfg *config.Options, c *gin.Context) {
src, err := providers.FindProvider(ssid) src, err := providers.FindProvider(ssid)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find your provider: %w", err)}) c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find your provider: %s", err.Error())})
return return
} }
@ -81,8 +81,8 @@ func getProviderSettingsState(cfg *config.Options, c *gin.Context) {
uss.Provider = src uss.Provider = src
err = c.ShouldBindJSON(&uss) err = c.ShouldBindJSON(&uss)
if err != nil { if err != nil {
log.Printf("%s sends invalid ProviderSettingsState JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid ProviderSettingsState JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }

View File

@ -81,7 +81,7 @@ func ProviderSpecsHandler(c *gin.Context) {
src, err := providers.FindProvider(ssid) src, err := providers.FindProvider(ssid)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find provider: %w", err)}) c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find provider: %s", err.Error())})
return return
} }

View File

@ -86,7 +86,7 @@ func DecodeProvider(c *gin.Context) (*happydns.ProviderCombined, int, error) {
us, err := providers.FindProvider(ust.Type) us, err := providers.FindProvider(ust.Type)
if err != nil { if err != nil {
log.Printf("%s: unable to find provider %s: %w", c.ClientIP(), ust.Type, err) log.Printf("%s: unable to find provider %s: %s", c.ClientIP(), ust.Type, err.Error())
return nil, http.StatusInternalServerError, fmt.Errorf("Sorry, we were unable to find the kind of provider in our database. Please report this issue.") return nil, http.StatusInternalServerError, fmt.Errorf("Sorry, we were unable to find the kind of provider in our database. Please report this issue.")
} }
@ -140,7 +140,7 @@ func ProviderHandler(c *gin.Context) {
// Extract provider ID // Extract provider ID
pid, err := strconv.ParseInt(string(c.Param("pid")), 10, 64) pid, err := strconv.ParseInt(string(c.Param("pid")), 10, 64)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Invalid provider id: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Invalid provider id: %s", err.Error())})
return return
} }
@ -182,7 +182,7 @@ func addProvider(c *gin.Context) {
s, err := storage.MainStore.CreateProvider(user, src.Provider, src.Comment) s, err := storage.MainStore.CreateProvider(user, src.Provider, src.Comment)
if err != nil { if err != nil {
log.Println("%s unable to CreateProvider: %w", c.ClientIP(), err) log.Println("%s unable to CreateProvider: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create the given provider. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create the given provider. Please try again later."})
return return
} }
@ -203,7 +203,7 @@ func UpdateProvider(c *gin.Context) {
src.OwnerId = provider.OwnerId src.OwnerId = provider.OwnerId
if err := storage.MainStore.UpdateProvider(src); err != nil { if err := storage.MainStore.UpdateProvider(src); err != nil {
log.Println("%s unable to UpdateProvider: %w", c.ClientIP(), err) log.Println("%s unable to UpdateProvider: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update the provider. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update the provider. Please try again later."})
return return
} }
@ -218,7 +218,7 @@ func deleteProvider(c *gin.Context) {
// Check if the provider has no more domain associated // Check if the provider has no more domain associated
domains, err := storage.MainStore.GetDomains(user) domains, err := storage.MainStore.GetDomains(user)
if err != nil { if err != nil {
log.Println("%s unable to GetDomains for user id=%x email=%s: %w", c.ClientIP(), user.Id, user.Email, err) log.Println("%s unable to GetDomains for user id=%x email=%s: %s", c.ClientIP(), user.Id, user.Email, err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to perform this action. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to perform this action. Please try again later."})
return return
} }
@ -231,7 +231,7 @@ func deleteProvider(c *gin.Context) {
} }
if err := storage.MainStore.DeleteProvider(providermeta); err != nil { if err := storage.MainStore.DeleteProvider(providermeta); err != nil {
log.Println("%s unable to DeleteProvider %x for user id=%x email=%s: %w", c.ClientIP(), providermeta.Id, user.Id, user.Email, err) log.Println("%s unable to DeleteProvider %x for user id=%x email=%s: %s", c.ClientIP(), providermeta.Id, user.Id, user.Email, err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to delete your provider. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to delete your provider. Please try again later."})
return return
} }

View File

@ -108,8 +108,8 @@ func resolverQuestion(client dns.Client, resolver string, dn string, rrType uint
func runResolver(c *gin.Context) { func runResolver(c *gin.Context) {
var urr resolverRequest var urr resolverRequest
if err := c.ShouldBindJSON(&urr); err != nil { if err := c.ShouldBindJSON(&urr); err != nil {
log.Printf("%s sends invalid ResolverRequest JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid ResolverRequest JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -120,7 +120,7 @@ func runResolver(c *gin.Context) {
} else if urr.Resolver == "local" { } else if urr.Resolver == "local" {
cConf, err := dns.ClientConfigFromFile("/etc/resolv.conf") cConf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil { if err != nil {
log.Printf("%s unable to load ClientConfigFromFile: %w", c.ClientIP(), err) log.Printf("%s unable to load ClientConfigFromFile: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to perform the request. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to perform the request. Please try again later."})
return return
} }

View File

@ -74,7 +74,7 @@ func getServiceSettingsState(cfg *config.Options, c *gin.Context) {
pvr, err := svcs.FindService(psid) pvr, err := svcs.FindService(psid)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, fmt.Sprintf("Unable to find this service: %w", err)) c.AbortWithStatusJSON(http.StatusNotFound, fmt.Sprintf("Unable to find this service: %s", err.Error()))
return return
} }
@ -82,8 +82,8 @@ func getServiceSettingsState(cfg *config.Options, c *gin.Context) {
ups.Service = pvr ups.Service = pvr
err = c.ShouldBindJSON(&ups) err = c.ShouldBindJSON(&ups)
if err != nil { if err != nil {
log.Printf("%s sends invalid ServiceSettingsState JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid ServiceSettingsState JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }

View File

@ -91,7 +91,7 @@ func ServiceSpecsHandler(c *gin.Context) {
svc, err := svcs.FindSubService(ssid) svc, err := svcs.FindSubService(ssid)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find specs: %w", err)}) c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find specs: %s", err.Error())})
return return
} }

View File

@ -69,19 +69,19 @@ func analyzeDomain(c *gin.Context) {
provider, err := storage.MainStore.GetProvider(user, domain.IdProvider) provider, err := storage.MainStore.GetProvider(user, domain.IdProvider)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to get the related provider: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to get the related provider: %s", err.Error())})
return return
} }
zone, err := provider.ImportZone(domain) zone, err := provider.ImportZone(domain)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to import zone: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to import zone: %s", err.Error())})
return return
} }
services, defaultTTL, err := svcs.AnalyzeZone(domain.DomainName, zone) services, defaultTTL, err := svcs.AnalyzeZone(domain.DomainName, zone)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("An error occurs during analysis: %w", err)}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("An error occurs during analysis: %s", err.Error())})
return return
} }

View File

@ -112,13 +112,13 @@ func completeAuth(opts *config.Options, c *gin.Context, email string, service st
RegistrationTime: &now, RegistrationTime: &now,
} }
if err = storage.MainStore.CreateUser(usr); err != nil { if err = storage.MainStore.CreateUser(usr); err != nil {
log.Printf("%s: unable to CreateUser in completeAuth: %w", c.ClientIP(), err) log.Printf("%s: unable to CreateUser in completeAuth: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your account. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your account. Please try again later."})
return return
} }
log.Printf("%s: Creates new user after successful service=%q login %q\n", c.ClientIP(), service, usr) log.Printf("%s: Creates new user after successful service=%q login %q\n", c.ClientIP(), service, usr)
} else if usr, err = storage.MainStore.GetUserByEmail(email); err != nil { } else if usr, err = storage.MainStore.GetUserByEmail(email); err != nil {
log.Printf("%s: unable to find User in completeAuth: %w", c.ClientIP(), err) log.Printf("%s: unable to find User in completeAuth: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to access your account. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to access your account. Please try again later."})
return return
} }
@ -127,11 +127,11 @@ func completeAuth(opts *config.Options, c *gin.Context, email string, service st
var session *happydns.Session var session *happydns.Session
if session, err = happydns.NewSession(usr); err != nil { if session, err = happydns.NewSession(usr); err != nil {
log.Printf("%s: unable to NewSession in completeAuth: %w", c.ClientIP(), err) log.Printf("%s: unable to NewSession in completeAuth: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your session. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your session. Please try again later."})
return return
} else if err = storage.MainStore.CreateSession(session); err != nil { } else if err = storage.MainStore.CreateSession(session); err != nil {
log.Printf("%s: unable to CreateSession in completeAuth: %w", c.ClientIP(), err) log.Printf("%s: unable to CreateSession in completeAuth: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your session. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your session. Please try again later."})
return return
} }
@ -170,14 +170,14 @@ type loginForm struct {
func dummyAuth(opts *config.Options, c *gin.Context) { func dummyAuth(opts *config.Options, c *gin.Context) {
var lf loginForm var lf loginForm
if err := c.ShouldBindJSON(&lf); err != nil { if err := c.ShouldBindJSON(&lf); err != nil {
log.Printf("%s sends invalid LoginForm JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid LoginForm JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
user, err := storage.MainStore.GetUserByEmail(lf.Email) user, err := storage.MainStore.GetUserByEmail(lf.Email)
if err != nil { if err != nil {
log.Printf("%s user's email (%s) not found: %w", c.ClientIP(), lf.Email, err) log.Printf("%s user's email (%s) not found: %s", c.ClientIP(), lf.Email, err.Error())
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Invalid username or password."}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Invalid username or password."})
return return
} }
@ -188,14 +188,14 @@ func dummyAuth(opts *config.Options, c *gin.Context) {
func checkAuth(opts *config.Options, c *gin.Context) { func checkAuth(opts *config.Options, c *gin.Context) {
var lf loginForm var lf loginForm
if err := c.ShouldBindJSON(&lf); err != nil { if err := c.ShouldBindJSON(&lf); err != nil {
log.Printf("%s sends invalid LoginForm JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid LoginForm JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
user, err := storage.MainStore.GetUserByEmail(lf.Email) user, err := storage.MainStore.GetUserByEmail(lf.Email)
if err != nil { if err != nil {
log.Printf("%s user's email (%s) not found: %w", c.ClientIP(), lf.Email, err) log.Printf("%s user's email (%s) not found: %s", c.ClientIP(), lf.Email, err.Error())
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Invalid username or password."}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "Invalid username or password."})
return return
} }

View File

@ -102,8 +102,8 @@ func registerUser(opts *config.Options, c *gin.Context) {
var uu UploadedUser var uu UploadedUser
err := c.ShouldBindJSON(&uu) err := c.ShouldBindJSON(&uu)
if err != nil { if err != nil {
log.Printf("%s sends invalid User JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid User JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -133,13 +133,13 @@ func registerUser(opts *config.Options, c *gin.Context) {
user.Settings.Newsletter = uu.Newsletter user.Settings.Newsletter = uu.Newsletter
if err := storage.MainStore.CreateUser(user); err != nil { if err := storage.MainStore.CreateUser(user); err != nil {
log.Printf("%s: unable to CreateUser in registerUser: %w", c.ClientIP(), err) log.Printf("%s: unable to CreateUser in registerUser: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your account. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to create your account. Please try again later."})
return return
} }
if actions.SendValidationLink(opts, user); err != nil { if actions.SendValidationLink(opts, user); err != nil {
log.Printf("%s: unable to SendValidationLink in registerUser: %w", c.ClientIP(), err) log.Printf("%s: unable to SendValidationLink in registerUser: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent email validation link. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent email validation link. Please try again later."})
return return
} }
@ -153,22 +153,22 @@ func specialUserOperations(opts *config.Options, c *gin.Context) {
var uu UploadedUser var uu UploadedUser
err := c.ShouldBindJSON(&uu) err := c.ShouldBindJSON(&uu)
if err != nil { if err != nil {
log.Printf("%s sends invalid User JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid User JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
res := gin.H{"errmsg": "If this address exists in our database, you'll receive a new e-mail."} res := gin.H{"errmsg": "If this address exists in our database, you'll receive a new e-mail."}
if user, err := storage.MainStore.GetUserByEmail(uu.Email); err != nil { if user, err := storage.MainStore.GetUserByEmail(uu.Email); err != nil {
log.Printf("%c: unable to retrieve user %q: %w", c.ClientIP(), uu.Email, err) log.Printf("%c: unable to retrieve user %q: %s", c.ClientIP(), uu.Email, err.Error())
c.JSON(http.StatusOK, res) c.JSON(http.StatusOK, res)
return return
} else { } else {
if uu.Kind == "recovery" { if uu.Kind == "recovery" {
if user.EmailValidated == nil { if user.EmailValidated == nil {
if err = actions.SendValidationLink(opts, user); err != nil { if err = actions.SendValidationLink(opts, user); err != nil {
log.Printf("%s: unable to SendValidationLink in specialUserOperations: %w", c.ClientIP(), err) log.Printf("%s: unable to SendValidationLink in specialUserOperations: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent email validation link. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent email validation link. Please try again later."})
return return
} }
@ -176,13 +176,13 @@ func specialUserOperations(opts *config.Options, c *gin.Context) {
log.Printf("%s: Sent validation link to: %s", c.ClientIP(), user.Email) log.Printf("%s: Sent validation link to: %s", c.ClientIP(), user.Email)
} else { } else {
if err = actions.SendRecoveryLink(opts, user); err != nil { if err = actions.SendRecoveryLink(opts, user); err != nil {
log.Printf("%s: unable to SendRecoveryLink in specialUserOperations: %w", c.ClientIP(), err) log.Printf("%s: unable to SendRecoveryLink in specialUserOperations: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent accont recovery link. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent accont recovery link. Please try again later."})
return return
} }
if err := storage.MainStore.UpdateUser(user); err != nil { if err := storage.MainStore.UpdateUser(user); err != nil {
log.Printf("%s: unable to UpdateUser in specialUserOperations: %w", c.ClientIP(), err) log.Printf("%s: unable to UpdateUser in specialUserOperations: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
@ -197,7 +197,7 @@ func specialUserOperations(opts *config.Options, c *gin.Context) {
} }
if err = actions.SendValidationLink(opts, user); err != nil { if err = actions.SendValidationLink(opts, user); err != nil {
log.Printf("%s: unable to SendValidationLink 2 in specialUserOperations: %w", c.ClientIP(), err) log.Printf("%s: unable to SendValidationLink 2 in specialUserOperations: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent email validation link. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to sent email validation link. Please try again later."})
return return
} }
@ -239,15 +239,15 @@ func changeUserSettings(c *gin.Context) {
var us happydns.UserSettings var us happydns.UserSettings
if err := c.ShouldBindJSON(&us); err != nil { if err := c.ShouldBindJSON(&us); err != nil {
log.Printf("%s sends invalid UserSettings JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid UserSettings JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
user.Settings = us user.Settings = us
if err := storage.MainStore.UpdateUser(user); err != nil { if err := storage.MainStore.UpdateUser(user); err != nil {
log.Printf("%s: unable to UpdateUser in changeUserSettings: %w", c.ClientIP(), err) log.Printf("%s: unable to UpdateUser in changeUserSettings: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
@ -266,8 +266,8 @@ func changePassword(opts *config.Options, c *gin.Context) {
var lf passwordForm var lf passwordForm
if err := c.ShouldBindJSON(&lf); err != nil { if err := c.ShouldBindJSON(&lf); err != nil {
log.Printf("%s sends invalid passwordForm JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid passwordForm JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -282,7 +282,7 @@ func changePassword(opts *config.Options, c *gin.Context) {
} }
if err := user.DefinePassword(lf.Password); err != nil { if err := user.DefinePassword(lf.Password); err != nil {
log.Printf("%s: unable to DefinePassword in changePassword: %w", c.ClientIP(), err) log.Printf("%s: unable to DefinePassword in changePassword: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
@ -290,13 +290,13 @@ func changePassword(opts *config.Options, c *gin.Context) {
// Retrieve all user's sessions to disconnect them // Retrieve all user's sessions to disconnect them
sessions, err := storage.MainStore.GetUserSessions(user) sessions, err := storage.MainStore.GetUserSessions(user)
if err != nil { if err != nil {
log.Printf("%s: unable to GetUserSessions in changePassword: %w", c.ClientIP(), err) log.Printf("%s: unable to GetUserSessions in changePassword: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
if err = storage.MainStore.UpdateUser(user); err != nil { if err = storage.MainStore.UpdateUser(user); err != nil {
log.Printf("%s: unable to DefinePassword in changePassword: %w", c.ClientIP(), err) log.Printf("%s: unable to DefinePassword in changePassword: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
@ -306,7 +306,7 @@ func changePassword(opts *config.Options, c *gin.Context) {
for _, session := range sessions { for _, session := range sessions {
err = storage.MainStore.DeleteSession(session) err = storage.MainStore.DeleteSession(session)
if err != nil { if err != nil {
log.Println("%s: unable to delete session (password changed): %w", c.ClientIP(), err) log.Println("%s: unable to delete session (password changed): %s", c.ClientIP(), err.Error())
} }
} }
@ -318,8 +318,8 @@ func deleteUser(opts *config.Options, c *gin.Context) {
var lf passwordForm var lf passwordForm
if err := c.ShouldBindJSON(&lf); err != nil { if err := c.ShouldBindJSON(&lf); err != nil {
log.Printf("%s sends invalid passwordForm JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid passwordForm JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -331,13 +331,13 @@ func deleteUser(opts *config.Options, c *gin.Context) {
// Retrieve all user's sessions to disconnect them // Retrieve all user's sessions to disconnect them
sessions, err := storage.MainStore.GetUserSessions(user) sessions, err := storage.MainStore.GetUserSessions(user)
if err != nil { if err != nil {
log.Printf("%s: unable to GetUserSessions in deleteUser: %w", c.ClientIP(), err) log.Printf("%s: unable to GetUserSessions in deleteUser: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
if err = storage.MainStore.DeleteUser(user); err != nil { if err = storage.MainStore.DeleteUser(user); err != nil {
log.Printf("%s: unable to DefinePassword in deleteuser: %w", c.ClientIP(), err) log.Printf("%s: unable to DefinePassword in deleteuser: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
@ -347,7 +347,7 @@ func deleteUser(opts *config.Options, c *gin.Context) {
for _, session := range sessions { for _, session := range sessions {
err = storage.MainStore.DeleteSession(session) err = storage.MainStore.DeleteSession(session)
if err != nil { if err != nil {
log.Println("%s: unable to delete session (drop account): %w", c.ClientIP(), err) log.Println("%s: unable to delete session (drop account): %s", c.ClientIP(), err.Error())
} }
} }
@ -390,19 +390,19 @@ func validateUserAddress(c *gin.Context) {
var uav UploadedAddressValidation var uav UploadedAddressValidation
err := c.ShouldBindJSON(&uav) err := c.ShouldBindJSON(&uav)
if err != nil { if err != nil {
log.Printf("%s sends invalid AddressValidation JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid AddressValidation JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
if err := user.ValidateEmail(uav.Key); err != nil { if err := user.ValidateEmail(uav.Key); err != nil {
log.Printf("%s bad email validation key: %w", c.ClientIP(), err) log.Printf("%s bad email validation key: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Bad validation key: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Bad validation key: %s", err.Error())})
return return
} }
if err := storage.MainStore.UpdateUser(user); err != nil { if err := storage.MainStore.UpdateUser(user); err != nil {
log.Printf("%s: unable to UpdateUser in ValidateUserAddress: %w", c.ClientIP(), err) log.Printf("%s: unable to UpdateUser in ValidateUserAddress: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }
@ -421,8 +421,8 @@ func recoverUserAccount(c *gin.Context) {
var uar UploadedAccountRecovery var uar UploadedAccountRecovery
err := c.ShouldBindJSON(&uar) err := c.ShouldBindJSON(&uar)
if err != nil { if err != nil {
log.Printf("%s sends invalid AccountRecovey JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid AccountRecovey JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -447,7 +447,7 @@ func recoverUserAccount(c *gin.Context) {
} }
if err := storage.MainStore.UpdateUser(user); err != nil { if err := storage.MainStore.UpdateUser(user); err != nil {
log.Printf("%s: unable to UpdateUser in recoverUserAccount: %w", c.ClientIP(), err) log.Printf("%s: unable to UpdateUser in recoverUserAccount: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your profile. Please try again later."})
return return
} }

View File

@ -141,8 +141,8 @@ func addZoneService(c *gin.Context) {
usc := &happydns.ServiceCombined{} usc := &happydns.ServiceCombined{}
err := c.ShouldBindJSON(&usc) err := c.ShouldBindJSON(&usc)
if err != nil { if err != nil {
log.Printf("%s sends invalid service JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid service JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -153,13 +153,13 @@ func addZoneService(c *gin.Context) {
err = zone.AppendService(subdomain, domain.DomainName, usc) err = zone.AppendService(subdomain, domain.DomainName, usc)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to add service: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to add service: %s", err.Error())})
return return
} }
err = storage.MainStore.UpdateZone(zone) err = storage.MainStore.UpdateZone(zone)
if err != nil { if err != nil {
log.Printf("%s: Unable to UpdateZone in updateZoneService: %w", c.ClientIP(), err) log.Printf("%s: Unable to UpdateZone in updateZoneService: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your zone. Please retry later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your zone. Please retry later."})
return return
} }
@ -170,7 +170,7 @@ func addZoneService(c *gin.Context) {
func serviceIdHandler(c *gin.Context) { func serviceIdHandler(c *gin.Context) {
serviceid, err := hex.DecodeString(c.Param("serviceid")) serviceid, err := hex.DecodeString(c.Param("serviceid"))
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Bad service identifier: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Bad service identifier: %s", err.Error())})
return return
} }
@ -193,7 +193,7 @@ func importZone(c *gin.Context) {
provider, err := storage.MainStore.GetProvider(user, domain.IdProvider) provider, err := storage.MainStore.GetProvider(user, domain.IdProvider)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find your provider: %w", err)}) c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Unable to find your provider: %s", err.Error())})
return return
} }
@ -221,7 +221,7 @@ func importZone(c *gin.Context) {
// Create history zone // Create history zone
err = storage.MainStore.CreateZone(myZone) err = storage.MainStore.CreateZone(myZone)
if err != nil { if err != nil {
log.Printf("%s: unable to CreateZone in importZone: %w\n", c.ClientIP(), err.Error()) log.Printf("%s: unable to CreateZone in importZone: %s\n", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your zone."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your zone."})
return return
} }
@ -231,7 +231,7 @@ func importZone(c *gin.Context) {
// Create wip zone // Create wip zone
err = storage.MainStore.CreateZone(myZone) err = storage.MainStore.CreateZone(myZone)
if err != nil { if err != nil {
log.Printf("%s: unable to CreateZone2 in importZone: %w\n", c.ClientIP(), err.Error()) log.Printf("%s: unable to CreateZone2 in importZone: %s\n", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your zone."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your zone."})
return return
} }
@ -240,7 +240,7 @@ func importZone(c *gin.Context) {
err = storage.MainStore.UpdateDomain(domain) err = storage.MainStore.UpdateDomain(domain)
if err != nil { if err != nil {
log.Printf("%s: unable to UpdateDomain in importZone: %w\n", c.ClientIP(), err.Error()) log.Printf("%s: unable to UpdateDomain in importZone: %s\n", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your zone."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are unable to create your zone."})
return return
} }
@ -315,8 +315,8 @@ func applyZone(c *gin.Context) {
var wantedCorrections []string var wantedCorrections []string
err = c.ShouldBindJSON(&wantedCorrections) err = c.ShouldBindJSON(&wantedCorrections)
if err != nil { if err != nil {
log.Printf("%s sends invalid string array JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid string array JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
@ -399,14 +399,14 @@ func UpdateZoneService(c *gin.Context) {
usc := &happydns.ServiceCombined{} usc := &happydns.ServiceCombined{}
err := c.ShouldBindJSON(&usc) err := c.ShouldBindJSON(&usc)
if err != nil { if err != nil {
log.Printf("%s sends invalid domain JSON: %w", c.ClientIP(), err) log.Printf("%s sends invalid domain JSON: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %s", err.Error())})
return return
} }
err = zone.EraseService(usc.Domain, domain.DomainName, usc.Id, usc) err = zone.EraseService(usc.Domain, domain.DomainName, usc.Id, usc)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to delete service: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to delete service: %s", err.Error())})
return return
} }
@ -414,7 +414,7 @@ func UpdateZoneService(c *gin.Context) {
err = storage.MainStore.UpdateZone(zone) err = storage.MainStore.UpdateZone(zone)
if err != nil { if err != nil {
log.Printf("%s: Unable to UpdateZone in updateZoneService: %w", c.ClientIP(), err) log.Printf("%s: Unable to UpdateZone in updateZoneService: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your zone. Please retry later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your zone. Please retry later."})
return return
} }
@ -430,7 +430,7 @@ func deleteZoneService(c *gin.Context) {
err := zone.EraseService(subdomain, domain.DomainName, serviceid, nil) err := zone.EraseService(subdomain, domain.DomainName, serviceid, nil)
if err != nil { if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to delete service: %w", err)}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Unable to delete service: %s", err.Error())})
return return
} }
@ -438,7 +438,7 @@ func deleteZoneService(c *gin.Context) {
err = storage.MainStore.UpdateZone(zone) err = storage.MainStore.UpdateZone(zone)
if err != nil { if err != nil {
log.Printf("%s: Unable to UpdateZone in deleteZoneService: %w", c.ClientIP(), err) log.Printf("%s: Unable to UpdateZone in deleteZoneService: %s", c.ClientIP(), err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your zone. Please retry later."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update your zone. Please retry later."})
return return
} }