Merge pull request #5160 from ywk253100/180619_response_code

Parse the error got from jobservice, fix #5047
This commit is contained in:
Wenkai Yin 2018-06-22 17:17:26 +08:00 committed by GitHub
commit 66811b3289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"time" "time"
"github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/dao"
common_http "github.com/vmware/harbor/src/common/http"
common_job "github.com/vmware/harbor/src/common/job" common_job "github.com/vmware/harbor/src/common/job"
"github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/models"
"github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/common/utils/log"
@ -195,6 +196,12 @@ func (ra *RepJobAPI) GetLog() {
logBytes, err := utils.GetJobServiceClient().GetJobLog(job.UUID) logBytes, err := utils.GetJobServiceClient().GetJobLog(job.UUID)
if err != nil { if err != nil {
if httpErr, ok := err.(*common_http.Error); ok {
ra.RenderError(httpErr.Code, "")
log.Errorf(fmt.Sprintf("failed to get log of job %d: %d %s",
ra.jobID, httpErr.Code, httpErr.Message))
return
}
ra.HandleInternalServerError(fmt.Sprintf("failed to get log of job %s: %v", ra.HandleInternalServerError(fmt.Sprintf("failed to get log of job %s: %v",
job.UUID, err)) job.UUID, err))
return return

View File

@ -16,6 +16,7 @@ package api
import ( import (
"github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/dao"
common_http "github.com/vmware/harbor/src/common/http"
"github.com/vmware/harbor/src/common/utils/log" "github.com/vmware/harbor/src/common/utils/log"
"github.com/vmware/harbor/src/ui/utils" "github.com/vmware/harbor/src/ui/utils"
@ -65,6 +66,12 @@ func (sj *ScanJobAPI) Prepare() {
func (sj *ScanJobAPI) GetLog() { func (sj *ScanJobAPI) GetLog() {
logBytes, err := utils.GetJobServiceClient().GetJobLog(sj.jobUUID) logBytes, err := utils.GetJobServiceClient().GetJobLog(sj.jobUUID)
if err != nil { if err != nil {
if httpErr, ok := err.(*common_http.Error); ok {
sj.RenderError(httpErr.Code, "")
log.Errorf(fmt.Sprintf("failed to get log of job %d: %d %s",
sj.jobID, httpErr.Code, httpErr.Message))
return
}
sj.HandleInternalServerError(fmt.Sprintf("Failed to get job logs, uuid: %s, error: %v", sj.jobUUID, err)) sj.HandleInternalServerError(fmt.Sprintf("Failed to get job logs, uuid: %s, error: %v", sj.jobUUID, err))
return return
} }