Fix display of errors (%w is only for Errorf)
This commit is contained in:
parent
89a9c736ae
commit
4f375162a3
|
@ -70,13 +70,13 @@ func getAllDomains(c *gin.Context) {
|
|||
|
||||
users, err := storage.MainStore.GetUsers()
|
||||
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
|
||||
}
|
||||
for _, user := range users {
|
||||
usersDomains, err := storage.MainStore.GetDomains(user)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func newDomain(c *gin.Context) {
|
|||
ud := &happydns.Domain{}
|
||||
err := c.ShouldBindJSON(&ud)
|
||||
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
|
||||
}
|
||||
ud.Id = 0
|
||||
|
@ -107,7 +107,7 @@ func updateUserDomain(c *gin.Context) {
|
|||
ud := &happydns.Domain{}
|
||||
err := c.ShouldBindJSON(&ud)
|
||||
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
|
||||
}
|
||||
ud.Id = domain.Id
|
||||
|
|
|
@ -98,7 +98,7 @@ func newUserProvider(c *gin.Context) {
|
|||
|
||||
us, _, err := api.DecodeProvider(c)
|
||||
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
|
||||
}
|
||||
us.Id = 0
|
||||
|
|
|
@ -103,7 +103,7 @@ func newUser(c *gin.Context) {
|
|||
uu := &happydns.User{}
|
||||
err := c.ShouldBindJSON(&uu)
|
||||
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
|
||||
}
|
||||
uu.Id = 0
|
||||
|
@ -127,7 +127,7 @@ func updateUser(c *gin.Context) {
|
|||
uu := &happydns.User{}
|
||||
err := c.ShouldBindJSON(&uu)
|
||||
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
|
||||
}
|
||||
uu.Id = user.Id
|
||||
|
@ -163,7 +163,7 @@ func resetUserPasswd(c *gin.Context) {
|
|||
urp := &resetPassword{}
|
||||
err := c.ShouldBindJSON(&urp)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ func updateUserDomainZones(c *gin.Context) {
|
|||
|
||||
err := c.ShouldBindJSON(&domain.ZoneHistory)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ func newUserDomainZone(c *gin.Context) {
|
|||
uz := &happydns.Zone{}
|
||||
err := c.ShouldBindJSON(&uz)
|
||||
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
|
||||
}
|
||||
uz.Id = 0
|
||||
|
@ -99,7 +99,7 @@ func updateZone(c *gin.Context) {
|
|||
uz := &happydns.Zone{}
|
||||
err := c.ShouldBindJSON(&uz)
|
||||
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
|
||||
}
|
||||
uz.Id = zone.Id
|
||||
|
@ -134,7 +134,7 @@ func updateZoneService(c *gin.Context) {
|
|||
usc := &happydns.ServiceCombined{}
|
||||
err = c.ShouldBindJSON(&usc)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ func patchZoneService(c *gin.Context) {
|
|||
usc := &happydns.ServiceCombined{}
|
||||
err := c.ShouldBindJSON(&usc)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,12 @@ func authMiddleware(opts *config.Options, optional bool) gin.HandlerFunc {
|
|||
if cookie, err := c.Cookie(COOKIE_NAME); err == nil {
|
||||
if sessionid, err = base64.StdEncoding.DecodeString(cookie); err != nil {
|
||||
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
|
||||
}
|
||||
} else if flds := strings.Fields(c.GetHeader("Authorization")); len(flds) == 2 && flds[0] == "Bearer" {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func authMiddleware(opts *config.Options, optional bool) gin.HandlerFunc {
|
|||
|
||||
session, err := storage.MainStore.GetSession(sessionid)
|
||||
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.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Your session has expired. Please reconnect.")})
|
||||
return
|
||||
|
@ -82,7 +82,7 @@ func authMiddleware(opts *config.Options, optional bool) gin.HandlerFunc {
|
|||
|
||||
user, err := storage.MainStore.GetUser(session.IdUser)
|
||||
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.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": fmt.Sprintf("Something goes wrong with your session. Please reconnect.")})
|
||||
return
|
||||
|
|
|
@ -65,7 +65,7 @@ func GetDomains(c *gin.Context) {
|
|||
}
|
||||
|
||||
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})
|
||||
} else if len(domains) > 0 {
|
||||
c.JSON(http.StatusOK, domains)
|
||||
|
@ -78,8 +78,8 @@ func addDomain(c *gin.Context) {
|
|||
var uz happydns.Domain
|
||||
err := c.ShouldBindJSON(&uz)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid Domain JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ func addDomain(c *gin.Context) {
|
|||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
} 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."})
|
||||
return
|
||||
} else {
|
||||
|
@ -172,7 +172,7 @@ func GetDomain(c *gin.Context) {
|
|||
zoneMeta, err := storage.MainStore.GetZoneMeta(zm)
|
||||
|
||||
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 {
|
||||
ret.ZoneHistory = append(ret.ZoneHistory, *zoneMeta)
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ func GetDomain(c *gin.Context) {
|
|||
|
||||
func delDomain(c *gin.Context) {
|
||||
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())})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func getProviderSettingsState(cfg *config.Options, c *gin.Context) {
|
|||
|
||||
src, err := providers.FindProvider(ssid)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,8 @@ func getProviderSettingsState(cfg *config.Options, c *gin.Context) {
|
|||
uss.Provider = src
|
||||
err = c.ShouldBindJSON(&uss)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid ProviderSettingsState JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func ProviderSpecsHandler(c *gin.Context) {
|
|||
|
||||
src, err := providers.FindProvider(ssid)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ func DecodeProvider(c *gin.Context) (*happydns.ProviderCombined, int, error) {
|
|||
|
||||
us, err := providers.FindProvider(ust.Type)
|
||||
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.")
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ func ProviderHandler(c *gin.Context) {
|
|||
// Extract provider ID
|
||||
pid, err := strconv.ParseInt(string(c.Param("pid")), 10, 64)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ func addProvider(c *gin.Context) {
|
|||
|
||||
s, err := storage.MainStore.CreateProvider(user, src.Provider, src.Comment)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ func UpdateProvider(c *gin.Context) {
|
|||
src.OwnerId = provider.OwnerId
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func deleteProvider(c *gin.Context) {
|
|||
// Check if the provider has no more domain associated
|
||||
domains, err := storage.MainStore.GetDomains(user)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ func deleteProvider(c *gin.Context) {
|
|||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -108,8 +108,8 @@ func resolverQuestion(client dns.Client, resolver string, dn string, rrType uint
|
|||
func runResolver(c *gin.Context) {
|
||||
var urr resolverRequest
|
||||
if err := c.ShouldBindJSON(&urr); err != nil {
|
||||
log.Printf("%s sends invalid ResolverRequest JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ func runResolver(c *gin.Context) {
|
|||
} else if urr.Resolver == "local" {
|
||||
cConf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func getServiceSettingsState(cfg *config.Options, c *gin.Context) {
|
|||
|
||||
pvr, err := svcs.FindService(psid)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,8 @@ func getServiceSettingsState(cfg *config.Options, c *gin.Context) {
|
|||
ups.Service = pvr
|
||||
err = c.ShouldBindJSON(&ups)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid ServiceSettingsState JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ func ServiceSpecsHandler(c *gin.Context) {
|
|||
|
||||
svc, err := svcs.FindSubService(ssid)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -69,19 +69,19 @@ func analyzeDomain(c *gin.Context) {
|
|||
|
||||
provider, err := storage.MainStore.GetProvider(user, domain.IdProvider)
|
||||
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
|
||||
}
|
||||
|
||||
zone, err := provider.ImportZone(domain)
|
||||
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
|
||||
}
|
||||
|
||||
services, defaultTTL, err := svcs.AnalyzeZone(domain.DomainName, zone)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -112,13 +112,13 @@ func completeAuth(opts *config.Options, c *gin.Context, email string, service st
|
|||
RegistrationTime: &now,
|
||||
}
|
||||
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."})
|
||||
return
|
||||
}
|
||||
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 {
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -127,11 +127,11 @@ func completeAuth(opts *config.Options, c *gin.Context, email string, service st
|
|||
|
||||
var session *happydns.Session
|
||||
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."})
|
||||
return
|
||||
} 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."})
|
||||
return
|
||||
}
|
||||
|
@ -170,14 +170,14 @@ type loginForm struct {
|
|||
func dummyAuth(opts *config.Options, c *gin.Context) {
|
||||
var lf loginForm
|
||||
if err := c.ShouldBindJSON(&lf); err != nil {
|
||||
log.Printf("%s sends invalid LoginForm JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
user, err := storage.MainStore.GetUserByEmail(lf.Email)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -188,14 +188,14 @@ func dummyAuth(opts *config.Options, c *gin.Context) {
|
|||
func checkAuth(opts *config.Options, c *gin.Context) {
|
||||
var lf loginForm
|
||||
if err := c.ShouldBindJSON(&lf); err != nil {
|
||||
log.Printf("%s sends invalid LoginForm JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
user, err := storage.MainStore.GetUserByEmail(lf.Email)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
|
66
api/users.go
66
api/users.go
|
@ -102,8 +102,8 @@ func registerUser(opts *config.Options, c *gin.Context) {
|
|||
var uu UploadedUser
|
||||
err := c.ShouldBindJSON(&uu)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid User JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -133,13 +133,13 @@ func registerUser(opts *config.Options, c *gin.Context) {
|
|||
user.Settings.Newsletter = uu.Newsletter
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -153,22 +153,22 @@ func specialUserOperations(opts *config.Options, c *gin.Context) {
|
|||
var uu UploadedUser
|
||||
err := c.ShouldBindJSON(&uu)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid User JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
return
|
||||
} else {
|
||||
if uu.Kind == "recovery" {
|
||||
if user.EmailValidated == 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."})
|
||||
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)
|
||||
} else {
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ func specialUserOperations(opts *config.Options, c *gin.Context) {
|
|||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -239,15 +239,15 @@ func changeUserSettings(c *gin.Context) {
|
|||
|
||||
var us happydns.UserSettings
|
||||
if err := c.ShouldBindJSON(&us); err != nil {
|
||||
log.Printf("%s sends invalid UserSettings JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
user.Settings = us
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -266,8 +266,8 @@ func changePassword(opts *config.Options, c *gin.Context) {
|
|||
|
||||
var lf passwordForm
|
||||
if err := c.ShouldBindJSON(&lf); err != nil {
|
||||
log.Printf("%s sends invalid passwordForm JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ func changePassword(opts *config.Options, c *gin.Context) {
|
|||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -290,13 +290,13 @@ func changePassword(opts *config.Options, c *gin.Context) {
|
|||
// Retrieve all user's sessions to disconnect them
|
||||
sessions, err := storage.MainStore.GetUserSessions(user)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ func changePassword(opts *config.Options, c *gin.Context) {
|
|||
for _, session := range sessions {
|
||||
err = storage.MainStore.DeleteSession(session)
|
||||
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
|
||||
if err := c.ShouldBindJSON(&lf); err != nil {
|
||||
log.Printf("%s sends invalid passwordForm JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -331,13 +331,13 @@ func deleteUser(opts *config.Options, c *gin.Context) {
|
|||
// Retrieve all user's sessions to disconnect them
|
||||
sessions, err := storage.MainStore.GetUserSessions(user)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ func deleteUser(opts *config.Options, c *gin.Context) {
|
|||
for _, session := range sessions {
|
||||
err = storage.MainStore.DeleteSession(session)
|
||||
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
|
||||
err := c.ShouldBindJSON(&uav)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid AddressValidation JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
if err := user.ValidateEmail(uav.Key); err != nil {
|
||||
log.Printf("%s bad email validation key: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Bad validation key: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -421,8 +421,8 @@ func recoverUserAccount(c *gin.Context) {
|
|||
var uar UploadedAccountRecovery
|
||||
err := c.ShouldBindJSON(&uar)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid AccountRecovey JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -447,7 +447,7 @@ func recoverUserAccount(c *gin.Context) {
|
|||
}
|
||||
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
|
34
api/zones.go
34
api/zones.go
|
@ -141,8 +141,8 @@ func addZoneService(c *gin.Context) {
|
|||
usc := &happydns.ServiceCombined{}
|
||||
err := c.ShouldBindJSON(&usc)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid service JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -153,13 +153,13 @@ func addZoneService(c *gin.Context) {
|
|||
|
||||
err = zone.AppendService(subdomain, domain.DomainName, usc)
|
||||
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
|
||||
}
|
||||
|
||||
err = storage.MainStore.UpdateZone(zone)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ func addZoneService(c *gin.Context) {
|
|||
func serviceIdHandler(c *gin.Context) {
|
||||
serviceid, err := hex.DecodeString(c.Param("serviceid"))
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ func importZone(c *gin.Context) {
|
|||
|
||||
provider, err := storage.MainStore.GetProvider(user, domain.IdProvider)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ func importZone(c *gin.Context) {
|
|||
// Create history zone
|
||||
err = storage.MainStore.CreateZone(myZone)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ func importZone(c *gin.Context) {
|
|||
// Create wip zone
|
||||
err = storage.MainStore.CreateZone(myZone)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ func importZone(c *gin.Context) {
|
|||
|
||||
err = storage.MainStore.UpdateDomain(domain)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -315,8 +315,8 @@ func applyZone(c *gin.Context) {
|
|||
var wantedCorrections []string
|
||||
err = c.ShouldBindJSON(&wantedCorrections)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid string array JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -399,14 +399,14 @@ func UpdateZoneService(c *gin.Context) {
|
|||
usc := &happydns.ServiceCombined{}
|
||||
err := c.ShouldBindJSON(&usc)
|
||||
if err != nil {
|
||||
log.Printf("%s sends invalid domain JSON: %w", c.ClientIP(), err)
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something is wrong in received data: %w", 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: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
err = zone.EraseService(usc.Domain, domain.DomainName, usc.Id, usc)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -414,7 +414,7 @@ func UpdateZoneService(c *gin.Context) {
|
|||
|
||||
err = storage.MainStore.UpdateZone(zone)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ func deleteZoneService(c *gin.Context) {
|
|||
|
||||
err := zone.EraseService(subdomain, domain.DomainName, serviceid, 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
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ func deleteZoneService(c *gin.Context) {
|
|||
|
||||
err = storage.MainStore.UpdateZone(zone)
|
||||
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."})
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue