add user-friendly error

This commit is contained in:
MaysWind
2021-01-01 23:45:26 +08:00
parent 0211c49f99
commit 102c945aa0
5 changed files with 15 additions and 0 deletions
+10
View File
@@ -9,6 +9,7 @@ import (
"github.com/mayswind/lab/pkg/log"
"github.com/mayswind/lab/pkg/models"
"github.com/mayswind/lab/pkg/services"
"github.com/mayswind/lab/pkg/settings"
)
// UsersApi represents user api
@@ -27,6 +28,10 @@ var (
// UserRegisterHandler saves a new user by request parameters
func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Error) {
if !settings.Container.Current.EnableUserRegister {
return a.UserRegistrationNotAllowed(c)
}
var userRegisterReq models.UserRegisterRequest
err := c.ShouldBindJSON(&userRegisterReq)
@@ -76,6 +81,11 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
return authResp, nil
}
// UserRegistrationNotAllowed returns user registration not allowed error
func (a *UsersApi) UserRegistrationNotAllowed(c *core.Context) (interface{}, *errs.Error) {
return nil, errs.ErrUserRegistrationNotAllowed
}
// UserProfileHandler returns user profile of current user
func (a *UsersApi) UserProfileHandler(c *core.Context) (interface{}, *errs.Error) {
uid := c.GetCurrentUid()