Skip to content

Commit b5cb1b5

Browse files
committed
Handle no records found for the project case
1 parent 4c3a7fc commit b5cb1b5

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

analytics/handlers.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"DBHS/response"
66
"DBHS/utils"
77
"net/http"
8+
"strings"
89

910
"github.com/gorilla/mux"
1011
)
@@ -32,14 +33,16 @@ func CurrentStorage(app *config.Application) http.HandlerFunc {
3233
}
3334

3435
storage, apiErr := GetALLDatabaseStorage(r.Context(), config.DB, projectOid)
35-
if apiErr.Error() != nil {
36-
utils.ResponseHandler(w, r, apiErr)
36+
if len(storage) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) {
37+
response.NotFound(w, r, "No storage information found for the project", nil)
3738
return
3839
}
39-
if len(storage) == 0 {
40-
response.NotFound(w, r, "No storage information found for the project", nil)
40+
41+
if apiErr.Error() != nil {
42+
utils.ResponseHandler(w, r, apiErr)
4143
return
4244
}
45+
4346
response.OK(w, r, "Storage history retrieved successfully", storage)
4447
}
4548
}
@@ -67,6 +70,11 @@ func ExecutionTime(app *config.Application) http.HandlerFunc {
6770
}
6871

6972
stats, apiErr := GetALLExecutionTimeStats(r.Context(), config.DB, projectOid)
73+
if len(stats) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) {
74+
response.NotFound(w, r, "No execution time records found for the project", nil)
75+
return
76+
}
77+
7078
if apiErr.Error() != nil {
7179
utils.ResponseHandler(w, r, apiErr)
7280
return
@@ -99,6 +107,11 @@ func DatabaseUsage(app *config.Application) http.HandlerFunc {
99107
}
100108

101109
stats, apiErr := GetALLDatabaseUsageStats(r.Context(), config.DB, projectOid)
110+
if len(stats) == 0 || (apiErr.Error() != nil && strings.Contains(apiErr.Error().Error(), "cannot scan NULL into")) {
111+
response.NotFound(w, r, "No database usage records found for the project", nil)
112+
return
113+
}
114+
102115
if apiErr.Error() != nil {
103116
utils.ResponseHandler(w, r, apiErr)
104117
return

0 commit comments

Comments
 (0)