Skip to content

Commit

Permalink
Chang wording of error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrisbattarbee committed Mar 28, 2024
1 parent 68d527e commit 8f27f4c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 40 deletions.
37 changes: 17 additions & 20 deletions apiserver/internal/server/current_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ func (s *Server) currentStatus(context *gin.Context) {
return
}

statusPageInterface, found := s.statusPageCache.Get(statusPageUrl)
if !found {
context.JSON(http.StatusNotFound, gin.H{"error": "status page not known to statusphere"})
return
}

statusPageInterfaceCasted, ok := statusPageInterface.(api.StatusPage)
if !ok {
context.JSON(http.StatusInternalServerError, gin.H{"error": "failed to cast status page to api.StatusPage"})
return
}

if !statusPageInterfaceCasted.IsIndexed {
context.JSON(http.StatusOK, CurrentStatusResponse{Status: StatusUnknown, IsIndexed: false})
return
}

// Attempt to get the incidents from the cache
incidents, found, err := s.getCurrentIncidentsFromCache(ctx, statusPageUrl)
if err != nil {
Expand Down Expand Up @@ -70,26 +87,6 @@ func (s *Server) currentStatus(context *gin.Context) {
context.JSON(http.StatusOK, CurrentStatusResponse{Status: StatusDegraded, IsIndexed: true})
return
}
// Is the status page indexed?
// If not, return unknown
// If it is, return up

statusPageInterface, found := s.statusPageCache.Get(statusPageUrl)
if !found {
context.JSON(http.StatusNotFound, gin.H{"error": "status page not known to statusphere"})
return
}

statusPageInterfaceCasted, ok := statusPageInterface.(api.StatusPage)
if !ok {
context.JSON(http.StatusInternalServerError, gin.H{"error": "failed to cast status page to api.StatusPage"})
return
}

if !statusPageInterfaceCasted.IsIndexed {
context.JSON(http.StatusOK, CurrentStatusResponse{Status: StatusUnknown, IsIndexed: false})
return
}

context.JSON(http.StatusOK, CurrentStatusResponse{Status: StatusUp, IsIndexed: true})
}
Expand Down
20 changes: 19 additions & 1 deletion apiserver/internal/server/incidents.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type IncidentsResponse struct {
Incidents []api.Incident `json:"incidents"`
IsIndexed bool `json:"isIndexed"`
}

// incidents is a handler for the /incidents endpoint.
Expand All @@ -24,6 +25,23 @@ func (s *Server) incidents(context *gin.Context) {
return
}

statusPage, found := s.statusPageCache.Get(statusPageUrl)
if !found {
context.JSON(http.StatusNotFound, gin.H{"error": "status page not known to statusphere"})
return
}

statusPageCasted, ok := statusPage.(api.StatusPage)
if !ok {
context.JSON(http.StatusInternalServerError, gin.H{"error": "failed to cast status page"})
return
}

if !statusPageCasted.IsIndexed {
context.JSON(http.StatusOK, IncidentsResponse{Incidents: []api.Incident{}, IsIndexed: false})
return
}

// Attempt to get the incidents from the cache
incidents, found, err := s.getIncidentsFromCache(ctx, statusPageUrl)
if err != nil {
Expand All @@ -44,7 +62,7 @@ func (s *Server) incidents(context *gin.Context) {
return
}
if !found {
context.JSON(http.StatusNotFound, gin.H{"error": "status page not indexed"})
context.JSON(http.StatusNotFound, gin.H{"error": "status page not known to statusphere"})
return
}

Expand Down
4 changes: 2 additions & 2 deletions apiserver/internal/server/status_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Server) statusPage(context *gin.Context) {
if statusPageUrl != "" {
statusPage, found := s.statusPageCache.Get(statusPageUrl)
if !found {
context.JSON(http.StatusNotFound, gin.H{"error": "status page not indexed"})
context.JSON(http.StatusNotFound, gin.H{"error": "status page not known to statusphere"})
return
}
context.JSON(http.StatusOK, StatusPageResponse{StatusPage: statusPage.(api.StatusPage)})
Expand All @@ -44,6 +44,6 @@ func (s *Server) statusPage(context *gin.Context) {
return
}
}
context.JSON(http.StatusNotFound, gin.H{"error": "status page not indexed"})
context.JSON(http.StatusNotFound, gin.H{"error": "status page not known to statusphere"})
}
}
34 changes: 17 additions & 17 deletions common/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func (sla IncidentEventArray) Value() (driver.Value, error) {
}

type IncidentEvent struct {
Title string
Description string
Time time.Time
Title string `json:"title"`
Description string `json:"description"`
Time time.Time `json:"time"`
}

func NewIncidentEvent(title string, description string, time time.Time) IncidentEvent {
Expand All @@ -42,15 +42,15 @@ func NewIncidentEvent(title string, description string, time time.Time) Incident
}

type Incident struct {
Title string
Components []string `gorm:"column:components;type:jsonb"`
Events IncidentEventArray `gorm:"column:events;type:jsonb"`
StartTime time.Time `gorm:"secondarykey"`
EndTime *time.Time `gorm:"secondarykey"`
Description *string
DeepLink string `gorm:"primarykey"`
Impact Impact `gorm:"secondarykey"`
StatusPageUrl string `gorm:"secondarykey"`
Title string `json:"title"`
Components []string `gorm:"column:components;type:jsonb" json:"components"`
Events IncidentEventArray `gorm:"column:events;type:jsonb" json:"events"`
StartTime time.Time `gorm:"secondarykey" json:"startTime"`
EndTime *time.Time `gorm:"secondarykey" json:"endTime"`
Description *string `json:"description"`
DeepLink string `gorm:"primarykey" json:"deepLink"`
Impact Impact `gorm:"secondarykey" json:"impact"`
StatusPageUrl string `gorm:"secondarykey" json:"statusPageUrl"`
}

func NewIncident(title string, components []string, events []IncidentEvent, startTime time.Time, endTime *time.Time, description *string, deepLink string, impact Impact, statusPageUrl string) Incident {
Expand All @@ -68,13 +68,13 @@ func NewIncident(title string, components []string, events []IncidentEvent, star
}

type StatusPage struct {
Name string `gorm:"secondarykey"`
URL string `gorm:"primarykey"`
Name string `gorm:"secondarykey" json:"name"`
URL string `gorm:"primarykey" json:"url"`
// Used to determine if we should run a scrape for this status page
LastHistoricallyScraped time.Time
LastCurrentlyScraped time.Time
LastHistoricallyScraped time.Time `json:"lastHistoricallyScraped"`
LastCurrentlyScraped time.Time `json:"lastCurrentlyScraped"`
// IsIndexed is used to determine if the status page has ever been indexed in the search engine successfully
IsIndexed bool
IsIndexed bool `json:"isIndexed"`
}

func NewStatusPage(name string, url string) StatusPage {
Expand Down

0 comments on commit 8f27f4c

Please sign in to comment.