MM-22405: Display the translated message instead of error id (#20462)

For a config failure, we now translate the message and show
a user friendly string rather than the error id.

This makes things easier to debug and read.

https://mattermost.atlassian.net/browse/MM-22405

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-06-14 14:58:15 +05:30
коммит произвёл GitHub
родитель 48a9234d69
Коммит 8aa8f21bbb
3 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package config
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
@@ -842,7 +843,9 @@ func TestDatabaseStoreLoad(t *testing.T) {
err = ds.Load()
if assert.Error(t, err) {
assert.EqualError(t, err, "invalid config: Config.IsValid: model.config.is_valid.site_url.app_error, parse \"invalid\": invalid URI for request")
var appErr *model.AppError
require.True(t, errors.As(err, &appErr))
assert.Equal(t, appErr.Id, "model.config.is_valid.site_url.app_error")
}
})

Просмотреть файл

@@ -819,7 +819,9 @@ func TestFileStoreLoad(t *testing.T) {
err = fs.Load()
if assert.Error(t, err) {
assert.EqualError(t, err, "invalid config: Config.IsValid: model.config.is_valid.site_url.app_error, parse \"invalid\": invalid URI for request")
var appErr *model.AppError
require.True(t, errors.As(err, &appErr))
assert.Equal(t, appErr.Id, "model.config.is_valid.site_url.app_error")
}
})

Просмотреть файл

@@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/i18n"
"github.com/mattermost/mattermost-server/v6/utils/jsonutils"
)
@@ -293,8 +294,11 @@ func (s *Store) Load() error {
loadedCfg = applyEnvironmentMap(loadedCfg, GetEnvironment())
fixConfig(loadedCfg)
if err := loadedCfg.IsValid(); err != nil {
return errors.Wrap(err, "invalid config")
if appErr := loadedCfg.IsValid(); appErr != nil {
// Translating the error before displaying it in the console.
// Defaulting to english for server side language.
appErr.Translate(i18n.GetUserTranslations("en"))
return errors.Wrap(appErr, "invalid config")
}
// Backing up feature flags section in case we need to restore them later on.