feat(error): more error handling
added missing checks
This commit is contained in:
parent
5cc5a22d28
commit
92ef2c5059
@ -32,6 +32,14 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
|
|||||||
return models.Tag{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
|
return models.Tag{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tagName == "" {
|
||||||
|
return models.Tag{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagNameIsEmpty})
|
||||||
|
}
|
||||||
|
|
||||||
|
if tagType == "" {
|
||||||
|
return models.Tag{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagTypeIsEmpty})
|
||||||
|
}
|
||||||
|
|
||||||
tag := models.Tag{
|
tag := models.Tag{
|
||||||
Name: tagName,
|
Name: tagName,
|
||||||
Type: tagType,
|
Type: tagType,
|
||||||
@ -109,6 +117,10 @@ func DeleteTag(ctx context.Context, tagName models.TagName) 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(tagName) == 0 {
|
||||||
|
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.TagAliasNameIsEmpty})
|
||||||
|
}
|
||||||
|
|
||||||
result := client.WithContext(ctx).Delete(&tag, tagName)
|
result := client.WithContext(ctx).Delete(&tag, tagName)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
Loading…
Reference in New Issue
Block a user