Skip to content

Commit

Permalink
fix(reports): Updating response code for the not found (#77)
Browse files Browse the repository at this point in the history
Updating response code for the not found
  • Loading branch information
Jacobbrewer1 authored Feb 21, 2024
1 parent 5664b07 commit 37a71f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/summary/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ clean:
@echo "Cleaning up"
# Remove the bin directory
rm -rf bin
# Remove any SQLITE files
rm -rf *.db
rm -rf *.db-shm
rm -rf *.db-wal
8 changes: 7 additions & 1 deletion cmd/summary/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ func reportIDHandler(w http.ResponseWriter, r *http.Request) {

// Get the report from the database.
rep, err := dataaccess.DB.GetReport(r.Context(), id)
if err != nil {
if errors.Is(err, dataaccess.ErrNotFound) {
w.WriteHeader(http.StatusNotFound)
if err := json.NewEncoder(w).Encode(request.NewMessage("Report not found")); err != nil {
slog.Warn("Error encoding response", slog.String(logging.KeyError, err.Error()))
}
return
} else if err != nil {
if !errors.Is(err, context.Canceled) {
slog.Error("Error getting report", slog.String(logging.KeyError, err.Error()))
}
Expand Down

0 comments on commit 37a71f4

Please sign in to comment.