Skip to content

Commit

Permalink
fix(api): return 404 when log doesn't exist (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r authored Aug 26, 2024
1 parent 0f28017 commit efd5b04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions api/log/get_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package log

import (
"errors"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"gorm.io/gorm"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
Expand Down Expand Up @@ -85,9 +87,15 @@ func GetServiceLog(c *gin.Context) {
// send API call to capture the service logs
sl, err := database.FromContext(c).GetLogForService(ctx, s)
if err != nil {
retErr := fmt.Errorf("unable to get logs for service %s: %w", entry, err)
var status int
if errors.Is(err, gorm.ErrRecordNotFound) {
status = http.StatusNotFound
} else {
status = http.StatusInternalServerError
}

util.HandleError(c, http.StatusInternalServerError, retErr)
retErr := fmt.Errorf("unable to get logs for service %s: %w", entry, err)
util.HandleError(c, status, retErr)

return
}
Expand Down
12 changes: 10 additions & 2 deletions api/log/get_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package log

import (
"errors"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"gorm.io/gorm"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/build"
Expand Down Expand Up @@ -86,9 +88,15 @@ func GetStepLog(c *gin.Context) {
// send API call to capture the step logs
sl, err := database.FromContext(c).GetLogForStep(ctx, s)
if err != nil {
retErr := fmt.Errorf("unable to get logs for step %s: %w", entry, err)
var status int
if errors.Is(err, gorm.ErrRecordNotFound) {
status = http.StatusNotFound
} else {
status = http.StatusInternalServerError
}

util.HandleError(c, http.StatusInternalServerError, retErr)
retErr := fmt.Errorf("unable to get logs for step %s: %w", entry, err)
util.HandleError(c, status, retErr)

return
}
Expand Down

0 comments on commit efd5b04

Please sign in to comment.