Skip to content

Commit

Permalink
fix job status
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Oct 6, 2022
1 parent 3b81c5f commit 6538515
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
10 changes: 10 additions & 0 deletions server/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/goccy/go-json"
bigqueryv2 "google.golang.org/api/bigquery/v2"
)

// ServerError represents BigQuery errors.
Expand All @@ -28,6 +29,15 @@ type ErrorFormat struct {
Message string `json:"message"`
}

func (e *ServerError) ErrorProto() *bigqueryv2.ErrorProto {
return &bigqueryv2.ErrorProto{
Reason: string(e.Reason),
Location: e.Location,
DebugInfo: e.DebugInfo,
Message: e.Message,
}
}

func (e *ServerError) Response() []byte {
b, _ := json.Marshal(&ResponseError{
Error: &ErrorFormat{
Expand Down
26 changes: 13 additions & 13 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (h *uploadContentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
job: job,
reader: r.Body,
}); err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
content := job.Content()
Expand Down Expand Up @@ -688,7 +688,7 @@ func (h *jobsCancelHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
job: job,
})
if err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down Expand Up @@ -717,7 +717,7 @@ func (h *jobsDeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
project: project,
job: job,
}); err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
}
Expand Down Expand Up @@ -758,7 +758,7 @@ func (h *jobsGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
job: job,
})
if err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down Expand Up @@ -787,7 +787,7 @@ func (h *jobsGetQueryResultsHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
job: job,
})
if err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down Expand Up @@ -831,7 +831,7 @@ func (h *jobsInsertHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
job: &job,
})
if err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down Expand Up @@ -924,13 +924,13 @@ func (h *jobsInsertHandler) Handle(ctx context.Context, r *jobsInsertRequest) (*
r.project.ID,
job.JobReference.JobId,
)
state := "DONE"
status := &bigqueryv2.JobStatus{State: "DONE"}
if jobErr != nil {
state = "FAILURE"
}
job.Status = &bigqueryv2.JobStatus{
State: state,
internalErr := errJobInternalError(jobErr.Error())
status.ErrorResult = internalErr.ErrorProto()
status.Errors = []*bigqueryv2.ErrorProto{internalErr.ErrorProto()}
}
job.Status = status
var totalBytes int64
if response != nil {
totalBytes = response.TotalBytes
Expand Down Expand Up @@ -978,7 +978,7 @@ func (h *jobsListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
project: project,
})
if err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down Expand Up @@ -1020,7 +1020,7 @@ func (h *jobsQueryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
queryRequest: &req,
})
if err != nil {
errorResponse(ctx, w, errInternalError(err.Error()))
errorResponse(ctx, w, errJobInternalError(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down

0 comments on commit 6538515

Please sign in to comment.