# HG changeset patch # User Sascha L. Teichmann # Date 1540387958 -7200 # Node ID c0f5dedf575341ba87a5af2daf5bc60347ed58f9 # Parent bf10a7f990ccfd2d5e17b25e17262e2c8fae514b Check first if we have a import before generating log import entries list. diff -r bf10a7f990cc -r c0f5dedf5753 pkg/controllers/importqueue.go --- a/pkg/controllers/importqueue.go Wed Oct 24 15:09:06 2018 +0200 +++ b/pkg/controllers/importqueue.go Wed Oct 24 15:32:38 2018 +0200 @@ -15,6 +15,7 @@ import ( "database/sql" + "fmt" "net/http" "strconv" @@ -36,6 +37,9 @@ selectImportPagedSQL = selectImportsUnpagedSQL + ` LIMIT $1 OFFSET $2` + selectHasImportSQL = ` +SELECT true FROM Waterway.imports WHERE id = $1` + selectImportLogsSQL = ` SELECT time, @@ -107,11 +111,28 @@ req *http.Request, conn *sql.Conn, ) (jr JSONResult, err error) { + + ctx := req.Context() + id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) - var rows *sql.Rows + // Check if he have such a import job first. + var dummy bool + err = conn.QueryRowContext(ctx, selectHasImportSQL, id).Scan(&dummy) + switch { + case err == sql.ErrNoRows: + err = JSONError{ + Code: http.StatusNotFound, + Message: fmt.Sprintf("Cannot find import #%d.", id), + } + return + case err != nil: + return + } - rows, err = conn.QueryContext(req.Context(), selectImportLogsSQL, id) + // We have it -> generate log entries. + var rows *sql.Rows + rows, err = conn.QueryContext(ctx, selectImportLogsSQL, id) if err != nil { return }