Merge pull request #9607 from jwangyangls/fix-delete-repositories-error

Fix the error when delete some images
This commit is contained in:
jwangyangls 2019-10-29 15:49:29 +08:00 committed by GitHub
commit 26453e8806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 4 deletions

View File

@ -181,6 +181,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
}, error => {
this.errorHandler.error(error);
this.loading = false;
this.refresh();
});
}
}

View File

@ -1,3 +1,5 @@
import { errorSrcWithoutHttpClient } from "ngx-markdown";
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -11,9 +13,27 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* handle docker client response error
* {"code":412,"message":"{\"errors\":[{\"code\":\"DENIED\",\"message\":\"Failed to process request,
* due to 'golang1:test1' is a immutable tag.\",\"detail\":\"Failed to process request,
* due to 'golang1:test1' is a immutable tag.\"}]}\n"}
* @param errorString string
*/
const errorHandlerForDockerClient = function (errorString: string): string {
try {
const errorMsgBody = JSON.parse(errorString);
if (errorMsgBody.errors && errorMsgBody.errors[0] && errorMsgBody.errors[0].message) {
return errorMsgBody.errors[0].message;
}
} catch (err) { }
return errorString;
};
/**
* To handle the error message body
*
* Standard error return format {code : number, message: string} / {error: {code: number, message: string},...}
**
* returns {string}
*/
@ -22,19 +42,27 @@ export const errorHandler = function (error: any): string {
if (!error) {
return "UNKNOWN_ERROR";
}
// Not a standard error return Basically not used cover unknown error
try {
return JSON.parse(error.error).message;
} catch (err) { }
// Not a standard error return Basically not used cover unknown error
if (typeof error.error === "string") {
return error.error;
}
if (error.error && error.error.message) {
return error.error.message;
if (typeof error.error.message === "string") {
// handle docker client response error
return errorHandlerForDockerClient(error.error.message);
}
}
if (error.message) {
return error.message;
// handle docker client response error
if (typeof error.message === "string") {
return errorHandlerForDockerClient(error.message);
}
}
// Not a standard error return Basically not used cover unknown error
if (!(error.statusCode || error.status)) {
// treat as string message
return '' + error;