feat(error): more error handling

added missing checks
This commit is contained in:
SoXX 2024-08-13 14:44:27 +02:00
parent a9ac2a34fb
commit 5562d75e3a

View File

@ -32,6 +32,14 @@ func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagNa
return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if tagAliasName == "" {
return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagAliasNameIsEmpty})
}
if tagName == "" {
return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagNameIsEmpty})
}
tagAlias := models.TagAlias{ tagAlias := models.TagAlias{
Name: tagAliasName, Name: tagAliasName,
TagID: tagName, TagID: tagName,
@ -109,6 +117,10 @@ func DeleteTagAlias(ctx context.Context, tagAliasName models.TagAliasName) error
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if len(tagAliasName) == 0 {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.TagAliasNameIsEmpty})
}
result := client.WithContext(ctx).Delete(&tagAlias, tagAliasName) result := client.WithContext(ctx).Delete(&tagAlias, tagAliasName)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {