mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 00:09:40 +02:00
feat(container): add a deletion generic handler used for container/network deletion
This commit is contained in:
parent
4b979628b3
commit
fb982ca8f1
4 changed files with 48 additions and 32 deletions
|
@ -21,6 +21,29 @@ function jsonObjectsToArrayHandler(data) {
|
|||
return angular.fromJson(str);
|
||||
}
|
||||
|
||||
// The Docker API often returns an empty string on success (Docker 1.9 -> Docker 1.12).
|
||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||
// container the error (Docker = 1.12).
|
||||
// This handler returns an empty object on success or a newly created JSON object with
|
||||
// the field message containing the error message on failure.
|
||||
// Used by the API in: container deletion, network deletion.
|
||||
function deleteGenericHandler(data) {
|
||||
var response = {};
|
||||
// No data is returned when deletion is successful (Docker 1.9 -> 1.12)
|
||||
if (!data) {
|
||||
return response;
|
||||
}
|
||||
// A string is returned on failure (Docker < 1.12)
|
||||
else if (!isJSON(data)) {
|
||||
response.message = data;
|
||||
}
|
||||
// Docker 1.12 returns a valid JSON object when an error occurs
|
||||
else {
|
||||
response = angular.fromJson(data);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
// Image delete API returns an array on success (Docker 1.9 -> Docker 1.12).
|
||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||
// container the error (Docker = 1.12).
|
||||
|
@ -43,26 +66,3 @@ function deleteImageHandler(data) {
|
|||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
// Network delete API returns an empty string on success (Docker 1.9 -> Docker 1.12).
|
||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||
// container the error (Docker = 1.12).
|
||||
// This handler returns an empty object on success or a newly created JSON object with
|
||||
// the field message containing the error message on failure.
|
||||
function deleteNetworkHandler(data) {
|
||||
var response = {};
|
||||
// No data is returned when deletion is successful (Docker 1.9 -> 1.12)
|
||||
if (!data) {
|
||||
return response;
|
||||
}
|
||||
// A string is returned when an error occurs (Docker < 1.12)
|
||||
else if (data && !isJSON(data)) {
|
||||
response.message = data;
|
||||
return response;
|
||||
}
|
||||
// Docker 1.12 returns a valid JSON object when an error occurs
|
||||
else {
|
||||
response = angular.fromJson(data);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue