Fix the error when delete some images

Signed-off-by: Yogi_Wang <yawang@vmware.com>
fix #9604 fix #9603
This commit is contained in:
Yogi_Wang 2019-10-28 12:32:50 +08:00
parent 5c4c04a122
commit e7c7e7ac25
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;