Skip to content

Modern Docker Management, Designed for Everyone

fix: return 4xx instead of 500 for unknown records and invalid requests (#4596)

José M. Requena Plensd54c253a6ddc
diff --git a/backend/internal/event/handler.go b/backend/internal/event/handler.go
index 38f8ddf6c..1c1cc6e6f 100644
--- a/backend/internal/event/handler.go
+++ b/backend/internal/event/handler.go
@@ -7,6 +7,7 @@ import (
"github.com/getarcaneapp/arcane/types/v2/base"
"github.com/getarcaneapp/arcane/types/v2/event"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/pkg/utils/handlerutil"
)
@@ -118,7 +119,7 @@ func (h *EventHandler) DeleteEvent(ctx context.Context, input *DeleteEventInput)
}
if err := h.eventService.DeleteEvent(ctx, input.EventID); err != nil {
- return nil, huma.Error500InternalServerError("Failed to delete event: " + err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), "Failed to delete event: "+err.Error())
}
return handlerutil.MessageOutput("Event deleted successfully", ""), nil
diff --git a/backend/internal/event/service.go b/backend/internal/event/service.go
index 4c3aac2ae..4ab379155 100644
--- a/backend/internal/event/service.go
+++ b/backend/internal/event/service.go
@@ -28,6 +28,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/internal/config"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
"github.com/getarcaneapp/arcane/backend/v2/internal/event/children/correlation"
@@ -382,7 +383,7 @@ func (s *EventService) DeleteEvent(ctx context.Context, eventID string) error {
return fmt.Errorf("failed to delete event: %w", result.Error)
}
if result.RowsAffected == 0 {
- return errors.New("event not found")
+ return common.Classify(common.ErrNotFound, errors.New("event not found"))
}
return nil
})
diff --git a/backend/internal/gitrepo/service.go b/backend/internal/gitrepo/service.go
index 401b91df3..1a36f70cc 100644
--- a/backend/internal/gitrepo/service.go
+++ b/backend/internal/gitrepo/service.go
@@ -65,7 +65,7 @@ func (s *GitRepositoryService) GetRepositoryByID(ctx context.Context, id string)
var repository GitRepository
if err := s.db.WithContext(ctx).Where("id = ?", id).First(&repository).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
- return nil, errors.New("repository not found")
+ return nil, common.Classify(common.ErrNotFound, errors.New("repository not found"))
}
return nil, fmt.Errorf("failed to get repository: %w", err)
}
@@ -76,7 +76,7 @@ func (s *GitRepositoryService) GetRepositoryByName(ctx context.Context, name str
var repository GitRepository
if err := s.db.WithContext(ctx).Where("name = ?", name).First(&repository).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
- return nil, errors.New("repository not found")
+ return nil, common.Classify(common.ErrNotFound, errors.New("repository not found"))
}
return nil, fmt.Errorf("failed to get repository: %w", err)
}
@@ -305,7 +305,7 @@ func (s *GitRepositoryService) DeleteRepository(ctx context.Context, id string,
}
if count > 0 {
- return fmt.Errorf("repository is used by %d sync configuration(s)", count)
+ return common.Classify(common.ErrConflict, fmt.Errorf("repository is used by %d sync configuration(s)", count))
}
// Get repository info before deleting
diff --git a/backend/internal/notification/handler.go b/backend/internal/notification/handler.go
index 276981f0d..d64f8c514 100644
--- a/backend/internal/notification/handler.go
+++ b/backend/internal/notification/handler.go
@@ -213,6 +213,9 @@ func (h *NotificationHandler) DispatchNotification(ctx context.Context, input *D
if errors.Is(err, ErrUnauthorizedNotificationDispatch) {
return nil, huma.Error401Unauthorized("unauthorized")
}
+ if errors.Is(err, common.ErrValidation) {
+ return nil, huma.Error400BadRequest(err.Error())
+ }
return nil, huma.Error500InternalServerError("dispatch failed")
}
diff --git a/backend/internal/notification/service.go b/backend/internal/notification/service.go
index 865e484a2..912ab5d2b 100644
--- a/backend/internal/notification/service.go
+++ b/backend/internal/notification/service.go
@@ -26,6 +26,7 @@ import (
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"golang.org/x/sync/errgroup"
+ "gorm.io/gorm"
"github.com/getarcaneapp/arcane/backend/v2/internal/apns"
"github.com/getarcaneapp/arcane/backend/v2/internal/common"
@@ -277,27 +278,27 @@ func (s *NotificationService) deliverForTarget(ctx context.Context, target Notif
switch payload.Kind {
case notification.DispatchKindImageUpdate:
if payload.ImageUpdate == nil {
- return 0, errors.New("image update payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("image update payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
imageUpdate := payload.ImageUpdate
return s.sendImageUpdateNotificationForTarget(ctx, target, imageUpdate.ImageRef, &imageUpdate.UpdateInfo, notifications.NotificationEventImageUpdate)
case notification.DispatchKindBatchImageUpdate:
if payload.BatchImageUpdate == nil {
- return 0, errors.New("batch image update payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("batch image update payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
return s.sendBatchImageUpdateNotificationForTarget(ctx, target, payload.BatchImageUpdate.Updates)
case notification.DispatchKindContainerUpdate:
if payload.ContainerUpdate == nil {
- return 0, errors.New("container update payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("container update payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
update := payload.ContainerUpdate
return s.sendContainerUpdateNotificationForTarget(ctx, target, update.ContainerName, update.ImageRef, update.OldDigest, update.NewDigest)
case notification.DispatchKindBatchContainerUpdate:
if payload.BatchContainerUpdate == nil {
- return 0, errors.New("batch container update payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("batch container update payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
entries := make([]notifications.ContainerUpdateBatchEntry, 0, len(payload.BatchContainerUpdate.Updates))
@@ -312,19 +313,19 @@ func (s *NotificationService) deliverForTarget(ctx context.Context, target Notif
return s.sendBatchContainerUpdateNotificationForTarget(ctx, target, entries)
case notification.DispatchKindVulnerabilityFound:
if payload.VulnerabilityFound == nil {
- return 0, errors.New("vulnerability payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("vulnerability payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
return s.sendVulnerabilityNotificationForTarget(ctx, target, VulnerabilityNotificationPayload(*payload.VulnerabilityFound))
case notification.DispatchKindPruneReport:
if payload.PruneReport == nil {
- return 0, errors.New("prune report payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("prune report payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
return s.sendPruneReportNotificationForTarget(ctx, target, &payload.PruneReport.Result)
case notification.DispatchKindAutoHeal:
if payload.AutoHeal == nil {
- return 0, errors.New("auto-heal payload is required")
+ return 0, common.Classify(common.ErrValidation, errors.New("auto-heal payload is required"))
}
logManagerDispatchNotification(ctx, target, payload.Kind)
return s.sendAutoHealNotificationForTarget(ctx, target, payload.AutoHeal.ContainerName, payload.AutoHeal.ContainerID)
@@ -992,6 +993,9 @@ func (s *NotificationService) sendAutoHealNotificationForTarget(ctx context.Cont
// and returns a warning when a real notification of the tested kind would not send.
func (s *NotificationService) TestNotification(ctx context.Context, environmentID string, provider notifications.NotificationProvider, testType string) (string, error) {
setting, err := s.GetSettingsByProvider(ctx, provider)
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return "", common.Classify(common.ErrBadRequest, fmt.Errorf("please save your %s settings before testing", provider))
+ }
if err != nil {
return "", fmt.Errorf("please save your %s settings before testing", provider)
}
diff --git a/backend/internal/project/handler.go b/backend/internal/project/handler.go
index e78992465..0c2d46f13 100644
--- a/backend/internal/project/handler.go
+++ b/backend/internal/project/handler.go
@@ -400,7 +400,7 @@ func (h *ProjectHandler) DownProject(ctx context.Context, input *DownProjectInpu
if errors.Is(err, common.ErrProjectArchived) || errors.Is(err, common.ErrProjectEnvUnreadable) {
return huma.Error400BadRequest(err.Error())
}
- return huma.Error500InternalServerError("Failed to bring down project: " + err.Error())
+ return huma.NewError(common.ToAPIError(err).HTTPStatus(), "Failed to bring down project: "+err.Error())
},
})
}
@@ -583,7 +583,7 @@ func (h *ProjectHandler) DestroyProject(ctx context.Context, input *DestroyProje
return h.projectService.DestroyProject(runtimeCtx, projectID, mo.PointerToOption(kit.FromPtr(input.Body).RemoveFiles).OrElse(true), kit.FromPtr(input.Body).RemoveVolumes, user)
},
Error: func(err error) error {
- return huma.Error500InternalServerError("Failed to destroy project: " + err.Error())
+ return huma.NewError(common.ToAPIError(err).HTTPStatus(), "Failed to destroy project: "+err.Error())
},
})
}
@@ -792,7 +792,7 @@ func (h *ProjectHandler) ArchiveProject(ctx context.Context, input *ArchiveProje
if errors.Is(archiveProjectErr, common.ErrProjectMustBeStopped) {
return nil, huma.Error400BadRequest(archiveProjectErr.Error())
}
- return nil, huma.Error500InternalServerError("Failed to archive project: " + archiveProjectErr.Error())
+ return nil, huma.NewError(common.ToAPIError(archiveProjectErr).HTTPStatus(), "Failed to archive project: "+archiveProjectErr.Error())
}
return handlerutil.MessageOutput("Project archived successfully", ""), nil
@@ -809,7 +809,7 @@ func (h *ProjectHandler) UnarchiveProject(ctx context.Context, input *UnarchiveP
}
if unarchiveProjectErr := h.projectService.UnarchiveProject(ctx, input.ProjectID, *user); unarchiveProjectErr != nil {
- return nil, huma.Error500InternalServerError("Failed to unarchive project: " + unarchiveProjectErr.Error())
+ return nil, huma.NewError(common.ToAPIError(unarchiveProjectErr).HTTPStatus(), "Failed to unarchive project: "+unarchiveProjectErr.Error())
}
return handlerutil.MessageOutput("Project unarchived successfully", ""), nil
diff --git a/backend/internal/system/children/backup/children/volumes/service.go b/backend/internal/system/children/backup/children/volumes/service.go
index 35e54f236..cc69ae2fe 100644
--- a/backend/internal/system/children/backup/children/volumes/service.go
+++ b/backend/internal/system/children/backup/children/volumes/service.go
@@ -23,6 +23,7 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/activity"
"github.com/getarcaneapp/arcane/backend/v2/internal/backup"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
"github.com/getarcaneapp/arcane/backend/v2/internal/s3"
"github.com/getarcaneapp/arcane/backend/v2/internal/settings"
@@ -347,19 +348,19 @@ func (s *Service) ListOptions(ctx context.Context) ([]backuptypes.SystemVolumeBa
// prepareSystemVolumeBackups resolves the requested policy, takes the system admission, and selects the live volumes.
func (s *Service) prepareSystemVolumeBackups(ctx context.Context, request backuptypes.RunSystemVolumeBackupsRequest) (selectionInput, *runs.Lease, error) {
if request.PolicyID != "" && request.Custom != nil {
- return selectionInput{}, nil, errors.New("select a saved policy or custom configuration, not both")
+ return selectionInput{}, nil, common.Classify(common.ErrValidation, errors.New("select a saved policy or custom configuration, not both"))
}
if request.Custom != nil && !slices.Contains(
[]backuptypes.SystemBackupDestination{backuptypes.SystemBackupDestinationLocal, backuptypes.SystemBackupDestinationS3, backuptypes.SystemBackupDestinationLocalS3},
request.Custom.Destination,
) {
- return selectionInput{}, nil, errors.New("destination must be local, s3, or local_s3")
+ return selectionInput{}, nil, common.Classify(common.ErrValidation, errors.New("destination must be local, s3, or local_s3"))
}
policy, err := func() (*backuptypes.SystemVolumeBackupPolicy, error) {
if request.PolicyID != "" {
stored, loadErr := s.systemVolumeBackupPolicy(request.PolicyID)
if loadErr == nil && stored == nil {
- return nil, errors.New("system-managed volume backup policy not found")
+ return nil, common.Classify(common.ErrNotFound, errors.New("system-managed volume backup policy not found"))
}
return stored, loadErr
}
diff --git a/backend/internal/system/children/backup/handler.go b/backend/internal/system/children/backup/handler.go
index 75e3894d0..cbf53e780 100644
--- a/backend/internal/system/children/backup/handler.go
+++ b/backend/internal/system/children/backup/handler.go
@@ -241,7 +241,7 @@ func (h *Handler) Restore(ctx context.Context, input *RestoreSystemBackupInput)
return h.service.RestoreBackup(activityCtx, input.ID, input.Body.RecoveryKey)
})
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return handlerutil.MessageOutput("Arcane system restore started", activityID), nil
}
@@ -294,7 +294,7 @@ func (h *Handler) Upload(ctx context.Context, input *UploadSystemBackupInput) (*
return e
})
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return &SystemBackupOutput{Body: *run}, nil
}
@@ -312,7 +312,7 @@ func (h *Handler) Delete(ctx context.Context, input *DeleteSystemBackupInput) (*
return h.service.DeleteBackup(activityCtx, input.ID, input.Body.RecoveryKey)
})
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return handlerutil.MessageOutput("Arcane system backup deleted successfully", activityID), nil
}
diff --git a/backend/internal/system/children/backup/service.go b/backend/internal/system/children/backup/service.go
index 81f7f8c91..5610aeb2f 100644
--- a/backend/internal/system/children/backup/service.go
+++ b/backend/internal/system/children/backup/service.go
@@ -393,13 +393,13 @@ func (s *Service) remoteRepository(ctx context.Context, destinationID string) (b
func (s *Service) recoveryKey(ctx context.Context, supplied string) (string, error) {
if strings.TrimSpace(supplied) != "" {
if err := backup.ValidateRecoveryKey(supplied); err != nil {
- return "", err
+ return "", common.Classify(common.ErrValidation, err)
}
return supplied, nil
}
key, err := s.recoveryKeys.Get(ctx)
if errors.Is(err, backup.ErrRecoveryKeyNotConfigured) {
- return "", errors.New("enter the recovery key or configure one in system backups")
+ return "", common.Classify(common.ErrValidation, errors.New("enter the recovery key or configure one in system backups"))
}
if err != nil {
return "", err
@@ -433,7 +433,7 @@ func (s *Service) prepareBackup(ctx context.Context, trigger string, request bac
if request.PolicyID != "" {
policy, policyErr := s.store.Policy(ctx, request.PolicyID)
if policyErr == nil && policy == nil {
- return nil, errors.New("system backup policy not found")
+ return nil, common.Classify(common.ErrNotFound, errors.New("system backup policy not found"))
}
return policy, policyErr
}
@@ -455,17 +455,17 @@ func (s *Service) prepareBackup(ctx context.Context, trigger string, request bac
S3DestinationID: strings.TrimSpace(request.S3DestinationID),
}, nil
default:
- return nil, errors.New("unknown system backup destination")
+ return nil, common.Classify(common.ErrValidation, errors.New("unknown system backup destination"))
}
}()
if err != nil {
return nil, err
}
if !selected.LocalEnabled && !selected.S3Enabled {
- return nil, errors.New("select at least one system backup destination")
+ return nil, common.Classify(common.ErrValidation, errors.New("select at least one system backup destination"))
}
if selected.S3Enabled && selected.S3DestinationID == "" {
- return nil, errors.New("select an S3 destination for the system backup")
+ return nil, common.Classify(common.ErrValidation, errors.New("select an S3 destination for the system backup"))
}
run := &backuptypes.SystemBackupRun{
ID: "system-" + uuid.New().String(),
diff --git a/backend/internal/system/service.go b/backend/internal/system/service.go
index b117fbb93..e37ac2658 100644
--- a/backend/internal/system/service.go
+++ b/backend/internal/system/service.go
@@ -34,6 +34,7 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/activity"
"github.com/getarcaneapp/arcane/backend/v2/internal/backup"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/internal/config"
"github.com/getarcaneapp/arcane/backend/v2/internal/container"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
@@ -553,6 +554,9 @@ func (s *SystemService) backupStore(s3Destinations *s3.S3DestinationService) sys
Run: func(ctx context.Context, id string) (*backuptypes.SystemBackupRun, error) {
var run SystemBackupRun
if err := s.db.WithContext(ctx).Where("id = ?", id).First(&run).Error; err != nil {
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, common.Classify(common.ErrNotFound, errors.New("system backup not found"))
+ }
return nil, err
}
return new(run.ToDTO()), nil
diff --git a/backend/internal/template/handler.go b/backend/internal/template/handler.go
index 7364d8ff9..d227dff13 100644
--- a/backend/internal/template/handler.go
+++ b/backend/internal/template/handler.go
@@ -370,7 +370,7 @@ func (h *TemplateHandler) CreateRegistry(ctx context.Context, input *CreateTempl
Enabled: input.Body.Enabled,
}
if err := h.templateService.CreateRegistry(ctx, registry); err != nil {
- return nil, huma.Error500InternalServerError("Failed to create registry: " + err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), "Failed to create registry: "+err.Error())
}
var out template.TemplateRegistry
diff --git a/backend/internal/updater/handler.go b/backend/internal/updater/handler.go
index 32da440f1..e66046fac 100644
--- a/backend/internal/updater/handler.go
+++ b/backend/internal/updater/handler.go
@@ -134,7 +134,8 @@ func (h *UpdaterHandler) updateContainer(ctx context.Context, input *UpdateConta
func (h *UpdaterHandler) CheckProjectUpdates(ctx context.Context, input *updater.CheckProjectInput) (*handlerutil.Out[*project.UpdateInfo], error) {
result, err := h.updaterService.CheckProjectUpdates(ctx, input.ProjectID)
if err != nil {
- return nil, err
+ apiErr := common.ToAPIError(err)
+ return nil, huma.NewError(apiErr.HTTPStatus(), "Failed to check project updates: "+apiErr.Message)
}
return &handlerutil.Out[*project.UpdateInfo]{
Body: base.ApiResponse[*project.UpdateInfo]{
diff --git a/backend/internal/volume/children/backup/children/browser/handler.go b/backend/internal/volume/children/backup/children/browser/handler.go
index 1ae3de1dc..05fd97871 100644
--- a/backend/internal/volume/children/backup/children/browser/handler.go
+++ b/backend/internal/volume/children/backup/children/browser/handler.go
@@ -51,7 +51,7 @@ func (h *Handler) BackupHasPath(ctx context.Context, input *BackupHasPathInput)
exists, err := h.service.BackupHasPath(ctx, input.BackupID, input.Path)
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return &handlerutil.Out[BackupHasPathResponse]{
@@ -65,7 +65,7 @@ func (h *Handler) BackupHasPath(ctx context.Context, input *BackupHasPathInput)
func (h *Handler) ListBackupFiles(ctx context.Context, input *ListBackupFilesInput) (*handlerutil.Out[[]string], error) {
files, err := h.service.ListBackupFiles(ctx, input.BackupID)
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return &handlerutil.Out[[]string]{
@@ -83,7 +83,7 @@ func (h *Handler) BrowseBackupFiles(ctx context.Context, input *BrowseBackupFile
return nil, huma.Error400BadRequest(err.Error())
}
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return &handlerutil.Page[backup.BackupFileEntry]{Body: base.Paginated[backup.BackupFileEntry]{
Success: true, Data: items, Pagination: handlerutil.PaginationResponse(page),
diff --git a/backend/internal/volume/children/backup/children/restore/handler.go b/backend/internal/volume/children/backup/children/restore/handler.go
index d7cf5201b..715b4e33a 100644
--- a/backend/internal/volume/children/backup/children/restore/handler.go
+++ b/backend/internal/volume/children/backup/children/restore/handler.go
@@ -74,7 +74,7 @@ func (h *Handler) RestoreBackup(ctx context.Context, input *RestoreBackupInput)
return h.service.RestoreBackup(runtimeCtx, input.VolumeName, input.BackupID, *user)
})
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return handlerutil.MessageOutput("Restore initiated successfully", activityID), nil
}
@@ -110,7 +110,7 @@ func (h *Handler) RestoreBackupFiles(ctx context.Context, input *RestoreBackupFi
return nil, huma.Error400BadRequest(err.Error())
}
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return handlerutil.MessageOutput("Restore initiated successfully", activityID), nil
diff --git a/backend/internal/volume/children/backup/handler.go b/backend/internal/volume/children/backup/handler.go
index a8e332b3a..98c51bb82 100644
--- a/backend/internal/volume/children/backup/handler.go
+++ b/backend/internal/volume/children/backup/handler.go
@@ -16,6 +16,7 @@ import (
kit "go.getarcane.app/kit/pkg"
"github.com/getarcaneapp/arcane/backend/v2/internal/activity"
+ "github.com/getarcaneapp/arcane/backend/v2/internal/common"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
"github.com/getarcaneapp/arcane/backend/v2/internal/environment"
"github.com/getarcaneapp/arcane/backend/v2/internal/upload"
@@ -94,7 +95,7 @@ func (h *Handler) DownloadBackup(ctx context.Context, input *DownloadBackupInput
user, _ := userctx.CurrentUserFromContext(ctx)
reader, size, err := h.service.DownloadBackup(ctx, input.BackupID, user)
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return &huma.StreamResponse{
@@ -183,7 +184,7 @@ func (h *Handler) DeleteBackup(ctx context.Context, input *DeleteBackupInput) (*
return nil, huma.Error409Conflict(err.Error())
}
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
return handlerutil.MessageOutput("Backup deleted successfully", activityID), nil
}
@@ -235,7 +236,7 @@ func (h *Handler) UploadBackup(ctx context.Context, input *UploadBackupInput) (*
return nil, huma.Error409Conflict(err.Error())
}
if err != nil {
- return nil, huma.Error500InternalServerError(err.Error())
+ return nil, huma.NewError(common.ToAPIError(err).HTTPStatus(), err.Error())
}
uploaded.ActivityID = mo.EmptyableToOption(strings.TrimSpace(activityID)).ToPointer()
return &handlerutil.Out[*volume.Backup]{Body: base.ApiResponse[*volume.Backup]{Success: true, Data: uploaded}}, nil
diff --git a/backend/internal/volume/children/backup/service.go b/backend/internal/volume/children/backup/service.go
index bdf17248e..a2b7009ba 100644
--- a/backend/internal/volume/children/backup/service.go
+++ b/backend/internal/volume/children/backup/service.go
@@ -553,7 +553,7 @@ func (s *Service) UploadBackup(ctx context.Context, backupID, s3DestinationID st
return nil, errors.New("volume backup has already been uploaded")
}
if strings.TrimSpace(s3DestinationID) == "" {
- return nil, errors.New("select an S3 destination for the upload")
+ return nil, common.Classify(common.ErrValidation, errors.New("select an S3 destination for the upload"))
}
remoteRepository, err := s.remoteRusticRepository(ctx, s3DestinationID, "")
if err != nil {
diff --git a/backend/internal/volume/service.go b/backend/internal/volume/service.go
index 466caacb3..99d3ef77d 100644
--- a/backend/internal/volume/service.go
+++ b/backend/internal/volume/service.go
@@ -246,6 +246,9 @@ func (s *VolumeService) backupStore() volumebackup.Store {
Run: func(ctx context.Context, backupID string) (*volumetypes.Backup, error) {
var entry VolumeBackup
if err := s.db.WithContext(ctx).Where("id = ?", backupID).First(&entry).Error; err != nil {
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ return nil, common.Classify(common.ErrNotFound, errors.New("volume backup not found"))
+ }
return nil, err
}
return entry.recordInternal(), nil