Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change some more error logs to warnings #163

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions internal/api/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"time"

"github.com/algolia/algoliasearch-client-go/v3/algolia/errs"
"github.com/hashicorp-forge/hermes/internal/config"
"github.com/hashicorp-forge/hermes/pkg/algolia"
gw "github.com/hashicorp-forge/hermes/pkg/googleworkspace"
Expand Down Expand Up @@ -63,15 +64,27 @@ func DocumentHandler(
baseDocObj := &hcd.BaseDoc{}
err = ar.Docs.GetObject(docID, &baseDocObj)
if err != nil {
l.Error("error requesting base document object from Algolia",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
http.Error(w, "Error accessing document",
http.StatusInternalServerError)
return
// Handle 404 from Algolia and only log a warning.
if _, is404 := errs.IsAlgoliaErrWithCode(err, 404); is404 {
l.Warn("base document object not found",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
http.Error(w, "Document not found", http.StatusNotFound)
return
} else {
l.Error("error requesting base document object from Algolia",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
http.Error(w, "Error accessing document",
http.StatusInternalServerError)
return
}
}

// Create new document object of the proper doc type.
Expand Down
34 changes: 24 additions & 10 deletions internal/api/drafts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"strings"
"time"

"github.com/algolia/algoliasearch-client-go/v3/algolia/errs"
"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
"github.com/algolia/algoliasearch-client-go/v3/algolia/search"
"github.com/hashicorp/go-hclog"
"gorm.io/gorm"

"github.com/hashicorp-forge/hermes/internal/config"
"github.com/hashicorp-forge/hermes/pkg/algolia"
gw "github.com/hashicorp-forge/hermes/pkg/googleworkspace"
hcd "github.com/hashicorp-forge/hermes/pkg/hashicorpdocs"
"github.com/hashicorp-forge/hermes/pkg/models"
"github.com/hashicorp/go-hclog"
"gorm.io/gorm"
)

type DraftsRequest struct {
Expand Down Expand Up @@ -455,13 +455,27 @@ func DraftsDocumentHandler(
baseDocObj := &hcd.BaseDoc{}
err = ar.Drafts.GetObject(docId, &baseDocObj)
if err != nil {
l.Error("error requesting base document object from Algolia",
"error", err,
"doc_id", docId,
)
http.Error(w, "Error accessing draft document",
http.StatusInternalServerError)
return
// Handle 404 from Algolia and only log a warning.
if _, is404 := errs.IsAlgoliaErrWithCode(err, 404); is404 {
l.Warn("base document object not found",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docId,
)
http.Error(w, "Draft document not found", http.StatusNotFound)
return
} else {
l.Error("error requesting base document object from Algolia",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docId,
)
http.Error(w, "Error accessing draft document",
http.StatusInternalServerError)
return
}
}

// Create new document object of the proper doc type.
Expand Down
8 changes: 5 additions & 3 deletions internal/api/me_recently_viewed_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ func MeRecentlyViewedDocsHandler(
},
}
if err := doc.Get(db); err != nil {
// Log error but continue trying to get other recently viewed
// documents (for a better UX).
l.Error("error getting document in database",
// If we get an error, log it but don't return an error response
// because this would degrade UX.
// TODO: change this log back to an error when this handles incomplete
// data in the database.
l.Warn("error getting document in database",
"error", err,
"method", r.Method,
"path", r.URL.Path,
Expand Down