Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respond 404 when asked to delete unknown domain #20

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/handler/impl/domain_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package impl

import (
"errors"
"net/http"
"time"

Expand All @@ -9,6 +10,7 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/api/header"
"github.com/podengo-project/idmsvc-backend/internal/api/public"
"github.com/podengo-project/idmsvc-backend/internal/domain/model"
internal_errors "github.com/podengo-project/idmsvc-backend/internal/errors"
"github.com/podengo-project/idmsvc-backend/internal/interface/repository"
"github.com/redhatinsights/platform-go-middlewares/identity"
"gorm.io/gorm"
Expand Down Expand Up @@ -160,7 +162,15 @@ func (a *application) DeleteDomain(
orgId,
domain_uuid,
); err != nil {
return err
if errors.Is(err, gorm.ErrRecordNotFound) {
return internal_errors.NewHTTPErrorF(
http.StatusNotFound,
"cannot delete unknown domain '%s'.",
UUID.String(),
)
} else {
return err
}
}
if tx.Commit(); tx.Error != nil {
return err
Expand Down