Skip to content

Commit

Permalink
fix: error handling of malformed media types
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-fossati committed Dec 9, 2024
1 parent 3095339 commit 7f8b117
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions provisioning/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/veraison/services/capability"
"github.com/veraison/services/provisioning/provisioner"
"github.com/veraison/services/verification/verifier"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -70,11 +69,11 @@ func (o *Handler) Submit(c *gin.Context) {
isSupported, err := o.Provisioner.IsSupportedMediaType(mediaType)
if err != nil {
status := http.StatusInternalServerError
if errors.Unwrap(err) == verifier.ErrInputParam {
if errors.Unwrap(err) == provisioner.ErrInputParam {
status = http.StatusBadRequest
}

ReportProblem(c, status, fmt.Sprintf("could not check media type with verifier: %v", err))
ReportProblem(c, status, fmt.Sprintf("could not check media type with provisioner: %v", err))
return
}

Expand Down
4 changes: 2 additions & 2 deletions provisioning/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func New(vtsClient vtsclient.IVTSClient) IProvisioner {
}

func (p *Provisioner) IsSupportedMediaType(mt string) (bool, error) {
mt, err := api.NormalizeMediaType(mt)
normalizedMediaType, err := api.NormalizeMediaType(mt)
if err != nil {
return false, fmt.Errorf("%w: validation failed for %s (%v)", ErrInputParam, mt, err)
}
Expand All @@ -41,7 +41,7 @@ func (p *Provisioner) IsSupportedMediaType(mt string) (bool, error) {
}

for _, v := range mts.MediaTypes {
if v == mt {
if v == normalizedMediaType {
return true, nil
}
}
Expand Down

0 comments on commit 7f8b117

Please sign in to comment.