Parse the error got from jobservice, fix #5047

Parse the error got from jobservice, and return the corresponding HTTP code if it's a HTTP error to caller
This commit is contained in:
Wenkai Yin 79628 2018-06-19 13:30:06 +08:00
parent 2a77ed73dc
commit 078360a021
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"time"
"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"
"github.com/vmware/harbor/src/common/models"
"github.com/vmware/harbor/src/common/utils/log"
@ -195,6 +196,12 @@ func (ra *RepJobAPI) GetLog() {
logBytes, err := utils.GetJobServiceClient().GetJobLog(job.UUID)
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",
job.UUID, err))
return

View File

@ -16,6 +16,7 @@ package api
import (
"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/ui/utils"
@ -65,6 +66,12 @@ func (sj *ScanJobAPI) Prepare() {
func (sj *ScanJobAPI) GetLog() {
logBytes, err := utils.GetJobServiceClient().GetJobLog(sj.jobUUID)
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))
return
}