mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
Merge pull request #9607 from jwangyangls/fix-delete-repositories-error
Fix the error when delete some images
This commit is contained in:
commit
26453e8806
@ -181,6 +181,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
|
||||
}, error => {
|
||||
this.errorHandler.error(error);
|
||||
this.loading = false;
|
||||
this.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user