Prechádzať zdrojové kódy

Merge pull request #35022 from thaJeztah/fix-conflict-status-code

Fix conflicting container name producing 400 error instead of 409
Yong Tang 7 rokov pred
rodič
commit
f8806b18b4
2 zmenil súbory, kde vykonal 12 pridanie a 1 odobranie
  1. 11 0
      daemon/errors.go
  2. 1 1
      daemon/names.go

+ 11 - 0
daemon/errors.go

@@ -64,6 +64,17 @@ func errExecPaused(id string) error {
 	return stateConflictError{cause}
 	return stateConflictError{cause}
 }
 }
 
 
+type nameConflictError struct {
+	id   string
+	name string
+}
+
+func (e nameConflictError) Error() string {
+	return fmt.Sprintf("Conflict. The container name %q is already in use by container %q. You have to remove (or rename) that container to be able to reuse that name.", e.name, e.id)
+}
+
+func (nameConflictError) Conflict() {}
+
 type validationError struct {
 type validationError struct {
 	cause error
 	cause error
 }
 }

+ 1 - 1
daemon/names.go

@@ -69,7 +69,7 @@ func (daemon *Daemon) reserveName(id, name string) (string, error) {
 				logrus.Errorf("got unexpected error while looking up reserved name: %v", err)
 				logrus.Errorf("got unexpected error while looking up reserved name: %v", err)
 				return "", err
 				return "", err
 			}
 			}
-			return "", validationError{errors.Errorf("Conflict. The container name %q is already in use by container %q. You have to remove (or rename) that container to be able to reuse that name.", name, id)}
+			return "", nameConflictError{id: id, name: name}
 		}
 		}
 		return "", errors.Wrapf(err, "error reserving name: %q", name)
 		return "", errors.Wrapf(err, "error reserving name: %q", name)
 	}
 	}