Skip to content

Commit

Permalink
fix: 404 err handling for fetch all help center topics
Browse files Browse the repository at this point in the history
  • Loading branch information
uloamaka committed Aug 7, 2024
1 parent 01d53de commit 743a4e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/helpcenter/helpcenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (base *Controller) FetchAllTopics(c *gin.Context) {
topics, paginationResponse, err := service.GetPaginatedTopics(c, base.Db.Postgresql)
if err != nil {
if err == gorm.ErrRecordNotFound {
rd := utility.BuildErrorResponse(http.StatusNotFound, "error", "No Job post not found", err, nil)
rd := utility.BuildErrorResponse(http.StatusNotFound, "error", "Topics not found", err, nil)
c.JSON(http.StatusNotFound, rd)
} else {
rd := utility.BuildErrorResponse(http.StatusInternalServerError, "error", "Failed to fetch job post", err, nil)
rd := utility.BuildErrorResponse(http.StatusInternalServerError, "error", "Failed to fetch topics", err, nil)
c.JSON(http.StatusInternalServerError, rd)
}
return
Expand Down
5 changes: 5 additions & 0 deletions services/helpcenter/helpcenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func GetPaginatedTopics(c *gin.Context, db *gorm.DB) ([]HelpCntSummary, postgres
if err != nil {
return nil, paginationResponse, err
}

if len(helpCnts) == 0 {
return nil, paginationResponse, gorm.ErrRecordNotFound
}

var topicSummaries []HelpCntSummary
for _, Hlp := range helpCnts {
summary := HelpCntSummary{
Expand Down

0 comments on commit 743a4e8

Please sign in to comment.