[MM-33826] add more detailed S3 error messages (#17182)

Automatic Merge
Этот коммит содержится в:
Max Erenberg
2021-04-09 12:16:30 -04:00
коммит произвёл GitHub
родитель 565f65a0c3
Коммит 3a3ec001bf
6 изменённых файлов: 53 добавлений и 14 удалений

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

@@ -91,6 +91,17 @@ func (a *App) CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppErr
return nil
}
func connectionTestErrorToAppError(connTestErr error) *model.AppError {
switch err := connTestErr.(type) {
case *filestore.S3FileBackendAuthError:
return model.NewAppError("TestConnection", "api.file.test_connection_s3_auth.app_error", nil, err.Error(), http.StatusInternalServerError)
case *filestore.S3FileBackendNoBucketError:
return model.NewAppError("TestConnection", "api.file.test_connection_s3_bucket_does_not_exist.app_error", nil, err.Error(), http.StatusInternalServerError)
default:
return model.NewAppError("TestConnection", "api.file.test_connection.app_error", nil, connTestErr.Error(), http.StatusInternalServerError)
}
}
func (a *App) TestFileStoreConnection() *model.AppError {
backend, err := a.FileBackend()
if err != nil {
@@ -98,7 +109,7 @@ func (a *App) TestFileStoreConnection() *model.AppError {
}
nErr := backend.TestConnection()
if nErr != nil {
return model.NewAppError("TestConnection", "api.file.test_connection.app_error", nil, nErr.Error(), http.StatusInternalServerError)
return connectionTestErrorToAppError(nErr)
}
return nil
}
@@ -111,7 +122,7 @@ func (a *App) TestFileStoreConnectionWithConfig(cfg *model.FileSettings) *model.
}
nErr := backend.TestConnection()
if nErr != nil {
return model.NewAppError("TestConnection", "api.file.test_connection.app_error", nil, nErr.Error(), http.StatusInternalServerError)
return connectionTestErrorToAppError(nErr)
}
return nil
}

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

@@ -522,7 +522,7 @@ func NewServer(options ...Option) (*Server, error) {
} else {
nErr := backend.TestConnection()
if nErr != nil {
if errors.Is(nErr, filestore.ErrNoS3Bucket) {
if _, ok := nErr.(*filestore.S3FileBackendNoBucketError); ok {
nErr = backend.(*filestore.S3FileBackend).MakeBucket()
}
if nErr != nil {