From e7c7e7ac2537e7df076214e6f900e24d020ee301 Mon Sep 17 00:00:00 2001 From: Yogi_Wang Date: Mon, 28 Oct 2019 12:32:50 +0800 Subject: [PATCH] Fix the error when delete some images Signed-off-by: Yogi_Wang fix #9604 fix #9603 --- .../repository-gridview.component.ts | 1 + src/portal/lib/src/shared/shared.utils.ts | 36 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/portal/lib/src/repository-gridview/repository-gridview.component.ts b/src/portal/lib/src/repository-gridview/repository-gridview.component.ts index 62bd594ba..80a007a68 100644 --- a/src/portal/lib/src/repository-gridview/repository-gridview.component.ts +++ b/src/portal/lib/src/repository-gridview/repository-gridview.component.ts @@ -181,6 +181,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit { }, error => { this.errorHandler.error(error); this.loading = false; + this.refresh(); }); } } diff --git a/src/portal/lib/src/shared/shared.utils.ts b/src/portal/lib/src/shared/shared.utils.ts index 895c7815e..541d8cf92 100644 --- a/src/portal/lib/src/shared/shared.utils.ts +++ b/src/portal/lib/src/shared/shared.utils.ts @@ -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;