Skip to content

Commit

Permalink
Merge pull request agola-io#179 from sgotti/runservice_logshandler_im…
Browse files Browse the repository at this point in the history
…prove_errors

runservice: improve errors in logsHandler
  • Loading branch information
sgotti committed Nov 14, 2019
2 parents 7cb2918 + c633cdb commit 9cacc80
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/services/runservice/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ func (h *LogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if sendError {
switch {
case util.IsNotExist(err):
http.Error(w, err.Error(), http.StatusNotFound)
httpError(w, util.NewErrNotExist(errors.Errorf("log doesn't exist: %w", err)))
default:
http.Error(w, err.Error(), http.StatusInternalServerError)
httpError(w, err)
}
}
}
Expand Down Expand Up @@ -241,15 +241,18 @@ func (h *LogsHandler) readTaskLogs(ctx context.Context, runID, taskID string, se

et, err := store.GetExecutorTask(ctx, h.e, task.ID)
if err != nil {
if err == etcd.ErrKeyNotFound {
return util.NewErrNotExist(errors.Errorf("executor task with id %q doesn't exist", task.ID)), true
}
return err, true
}
executor, err := store.GetExecutor(ctx, h.e, et.Spec.ExecutorID)
if err != nil && err != etcd.ErrKeyNotFound {
if err != nil {
if err == etcd.ErrKeyNotFound {
return util.NewErrNotExist(errors.Errorf("executor with id %q doesn't exist", et.Spec.ExecutorID)), true
}
return err, true
}
if executor == nil {
return util.NewErrNotExist(errors.Errorf("executor with id %q doesn't exist", et.Spec.ExecutorID)), true
}

var url string
if setup {
Expand Down

0 comments on commit 9cacc80

Please sign in to comment.