mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-17 04:11:24 +01:00
Merge pull request #6169 from steven-zou/fix_issue_of_periodic_conflicts
Return 409 conflict error in liue of 200 with ID of existing one
This commit is contained in:
commit
dde6c39e80
@ -83,7 +83,13 @@ func (dh *DefaultHandler) HandleLaunchJobReq(w http.ResponseWriter, req *http.Re
|
||||
// Pass request to the controller for the follow-up.
|
||||
jobStats, err := dh.controller.LaunchJob(jobReq)
|
||||
if err != nil {
|
||||
dh.handleError(w, req, http.StatusInternalServerError, errs.LaunchJobError(err))
|
||||
if errs.IsConflictError(err) {
|
||||
// Conflict error
|
||||
dh.handleError(w, req, http.StatusConflict, err)
|
||||
} else {
|
||||
// General error
|
||||
dh.handleError(w, req, http.StatusInternalServerError, errs.LaunchJobError(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ package errs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -50,6 +51,8 @@ const (
|
||||
NoObjectFoundErrorCode
|
||||
// UnAuthorizedErrorCode is code for the error of unauthorized accessing
|
||||
UnAuthorizedErrorCode
|
||||
// ResourceConflictsErrorCode is code for the error of resource conflicting
|
||||
ResourceConflictsErrorCode
|
||||
)
|
||||
|
||||
// baseError ...
|
||||
@ -183,6 +186,22 @@ func NoObjectFoundError(object string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// conflictError is designed for the case of resource conflicting
|
||||
type conflictError struct {
|
||||
baseError
|
||||
}
|
||||
|
||||
// ConflictError is error for the case of resource conflicting
|
||||
func ConflictError(object string) error {
|
||||
return conflictError{
|
||||
baseError{
|
||||
Code: ResourceConflictsErrorCode,
|
||||
Err: "conflict",
|
||||
Description: fmt.Sprintf("the submitting resource is conflicted with existing one %s", object),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// IsJobStoppedError return true if the error is jobStoppedError
|
||||
func IsJobStoppedError(err error) bool {
|
||||
_, ok := err.(jobStoppedError)
|
||||
@ -200,3 +219,9 @@ func IsObjectNotFoundError(err error) bool {
|
||||
_, ok := err.(objectNotFoundError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsConflictError returns true if the error is conflictError
|
||||
func IsConflictError(err error) bool {
|
||||
_, ok := err.(conflictError)
|
||||
return ok
|
||||
}
|
||||
|
@ -120,8 +120,9 @@ func (rps *RedisPeriodicScheduler) Schedule(jobName string, params models.Parame
|
||||
// Check existing
|
||||
// If existing, treat as a succeed submitting and return the exitsing id
|
||||
if score, ok := rps.exists(string(rawJSON)); ok {
|
||||
id, err := rps.getIDByScore(score)
|
||||
return id, 0, err
|
||||
// Ignore error
|
||||
id, _ := rps.getIDByScore(score)
|
||||
return "", 0, errs.ConflictError(id)
|
||||
}
|
||||
|
||||
uuid, score := utils.MakePeriodicPolicyUUID()
|
||||
|
Loading…
Reference in New Issue
Block a user