1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 15:49:44 +02:00

wrap errors up, log at top level only

This commit is contained in:
Harvey Kandola 2017-08-03 10:00:24 +01:00
parent ecc94f31c9
commit 476403bf46
28 changed files with 899 additions and 804 deletions

View file

@ -65,14 +65,14 @@ func (h *Handler) GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
// We can link to a section within the same document so
// let's get all pages for the document and remove "us".
pages, err := h.Store.Page.GetPagesWithoutContent(ctx, documentID)
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
return
}
if len(pages) == 0 {
pages = []page.Page{}
}
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
pc := []link.Candidate{}
@ -93,15 +93,16 @@ func (h *Handler) GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
// We can link to attachment within the same document so
// let's get all attachments for the document.
files, err := h.Store.Attachment.GetAttachments(ctx, documentID)
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
return
}
if len(files) == 0 {
files = []attachment.Attachment{}
}
if err != nil && err != sql.ErrNoRows {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
fc := []link.Candidate{}
for _, f := range files {
@ -137,12 +138,13 @@ func (h *Handler) SearchLinkCandidates(w http.ResponseWriter, r *http.Request) {
keywords := request.Query(r, "keywords")
decoded, err := url.QueryUnescape(keywords)
if err != nil {
h.Runtime.Log.Error("decode query string", err)
h.Runtime.Log.Error(method, err)
}
docs, pages, attachments, err := h.Store.Link.SearchCandidates(ctx, decoded)
if err != nil {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}