mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
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:
parent
2a77ed73dc
commit
078360a021
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user