create CMS error handling
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"tm/pkg/logger"
|
||||
"tm/pkg/response"
|
||||
@@ -90,6 +91,9 @@ func (s *cmsService) GetByID(ctx context.Context, id string) (*CMSResponse, erro
|
||||
|
||||
cms, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrCMSNotFound) {
|
||||
return nil, ErrCMSNotFound
|
||||
}
|
||||
s.logger.Error("Failed to get CMS by ID", map[string]interface{}{
|
||||
"id": id,
|
||||
"error": err.Error(),
|
||||
@@ -108,6 +112,9 @@ func (s *cmsService) GetByKey(ctx context.Context, key string) (*CMSResponse, er
|
||||
|
||||
cms, err := s.repo.GetByKey(ctx, key)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrCMSNotFound) {
|
||||
return nil, ErrCMSNotFound
|
||||
}
|
||||
s.logger.Error("Failed to get CMS by key", map[string]interface{}{
|
||||
"key": key,
|
||||
"error": err.Error(),
|
||||
@@ -128,6 +135,9 @@ func (s *cmsService) Update(ctx context.Context, id string, form *CMSForm) (*CMS
|
||||
// Get existing CMS
|
||||
cms, err := s.repo.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrCMSNotFound) {
|
||||
return nil, ErrCMSNotFound
|
||||
}
|
||||
s.logger.Error("Failed to get existing CMS for update", map[string]interface{}{
|
||||
"id": id,
|
||||
"error": err.Error(),
|
||||
@@ -175,6 +185,9 @@ func (s *cmsService) Delete(ctx context.Context, id string) error {
|
||||
})
|
||||
|
||||
if err := s.repo.Delete(ctx, id); err != nil {
|
||||
if errors.Is(err, ErrCMSNotFound) {
|
||||
return ErrCMSNotFound
|
||||
}
|
||||
s.logger.Error("Failed to delete CMS", map[string]interface{}{
|
||||
"id": id,
|
||||
"error": err.Error(),
|
||||
|
||||
Reference in New Issue
Block a user