MM-30041: Return correct error message for user save (#16117)
* MM-30041: Return correct error message for user save We were collapsing all types of user conflict into a single error message. Fixed it by inspecting the field of the invalidError type and returning the correct message. https://mattermost.atlassian.net/browse/MM-30041 ```release-note NONE ``` * Fix test errors * Fix wrong message in test when comparing error messages Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1aadd36644
Коммит
325bff1176
22
app/bot.go
22
app/bot.go
@@ -26,7 +26,16 @@ func (a *App) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(nErr, &invErr):
|
||||
return nil, model.NewAppError("CreateBot", "app.user.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
code := ""
|
||||
switch invErr.Field {
|
||||
case "email":
|
||||
code = "app.user.save.email_exists.app_error"
|
||||
case "username":
|
||||
code = "app.user.save.username_exists.app_error"
|
||||
default:
|
||||
code = "app.user.save.existing.app_error"
|
||||
}
|
||||
return nil, model.NewAppError("CreateBot", code, nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return nil, model.NewAppError("CreateBot", "app.user.save.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
@@ -93,7 +102,16 @@ func (a *App) getOrCreateWarnMetricsBot(botDef *model.Bot) (*model.Bot, *model.A
|
||||
case errors.As(nErr, &appError):
|
||||
return nil, appError
|
||||
case errors.As(nErr, &invErr):
|
||||
return nil, model.NewAppError("getOrCreateWarnMetricsBot", "app.user.save.existing.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
code := ""
|
||||
switch invErr.Field {
|
||||
case "email":
|
||||
code = "app.user.save.email_exists.app_error"
|
||||
case "username":
|
||||
code = "app.user.save.username_exists.app_error"
|
||||
default:
|
||||
code = "app.user.save.existing.app_error"
|
||||
}
|
||||
return nil, model.NewAppError("getOrCreateWarnMetricsBot", code, nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return nil, model.NewAppError("getOrCreateWarnMetricsBot", "app.user.save.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user