diff --git a/service/config.go b/service/config.go index 1c31ba7..524934e 100644 --- a/service/config.go +++ b/service/config.go @@ -102,13 +102,13 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon config := upsertConfig.Config module := state.Modules().GetById(config.ModuleId) if module == nil { - return cluster.NewResponseErrorf(codes2.InvalidArgument, "invalid moduleId %s", config.ModuleId) + return cluster.NewResponseErrorf(codes2.NotFound, "moduleId %s not found", config.ModuleId) } if !upsertConfig.Unsafe { schemaStorage := state.Schemas().GetByModuleIds([]string{config.ModuleId}) if len(schemaStorage) == 0 { - return cluster.NewResponseErrorf(codes2.NotFound, "schema for moduleId %s not found", config.Id) + return cluster.NewResponseErrorf(codes2.NotFound, "schema for moduleId %s not found", config.ModuleId) } dataForValidate := cs.CompileConfig(config.Data, state, config.CommonConfigs...) @@ -189,16 +189,14 @@ func (configService) validateSchema(schema entity.ConfigSchema, data map[string] documentLoader := gojsonschema.NewGoLoader(data) if result, err := gojsonschema.Validate(schemaLoader, documentLoader); err != nil { return false, err - } else if len(result.Errors()) > 0 { + } else if result.Valid() { + return true, nil + } else { desc := make(map[string]string) for _, value := range result.Errors() { desc[value.Field()] = value.Description() } return false, validationSchemaError{Description: desc} - } else if result.Valid() { - return true, nil - } else { - return false, nil } }