mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-07 08:34:15 +01:00
Use http.Error instead of writer.Write
This commit is contained in:
parent
ab66e7ec8a
commit
5e711fb3b9
@ -43,13 +43,12 @@ func UptimeBadge(writer http.ResponseWriter, request *http.Request) {
|
|||||||
uptime, err := store.Get().GetUptimeByKey(key, from, time.Now())
|
uptime, err := store.Get().GetUptimeByKey(key, from, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == common.ErrEndpointNotFound {
|
if err == common.ErrEndpointNotFound {
|
||||||
writer.WriteHeader(http.StatusNotFound)
|
http.Error(writer, err.Error(), http.StatusNotFound)
|
||||||
} else if err == common.ErrInvalidTimeRange {
|
} else if err == common.ErrInvalidTimeRange {
|
||||||
writer.WriteHeader(http.StatusBadRequest)
|
http.Error(writer, err.Error(), http.StatusBadRequest)
|
||||||
} else {
|
} else {
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
_, _ = writer.Write([]byte(err.Error()))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
formattedDate := time.Now().Format(http.TimeFormat)
|
formattedDate := time.Now().Format(http.TimeFormat)
|
||||||
@ -82,13 +81,12 @@ func ResponseTimeBadge(writer http.ResponseWriter, request *http.Request) {
|
|||||||
averageResponseTime, err := store.Get().GetAverageResponseTimeByKey(key, from, time.Now())
|
averageResponseTime, err := store.Get().GetAverageResponseTimeByKey(key, from, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == common.ErrEndpointNotFound {
|
if err == common.ErrEndpointNotFound {
|
||||||
writer.WriteHeader(http.StatusNotFound)
|
http.Error(writer, err.Error(), http.StatusNotFound)
|
||||||
} else if err == common.ErrInvalidTimeRange {
|
} else if err == common.ErrInvalidTimeRange {
|
||||||
writer.WriteHeader(http.StatusBadRequest)
|
http.Error(writer, err.Error(), http.StatusBadRequest)
|
||||||
} else {
|
} else {
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
_, _ = writer.Write([]byte(err.Error()))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
formattedDate := time.Now().Format(http.TimeFormat)
|
formattedDate := time.Now().Format(http.TimeFormat)
|
||||||
|
@ -45,18 +45,16 @@ func ResponseTimeChart(writer http.ResponseWriter, r *http.Request) {
|
|||||||
hourlyAverageResponseTime, err := store.Get().GetHourlyAverageResponseTimeByKey(vars["key"], from, time.Now())
|
hourlyAverageResponseTime, err := store.Get().GetHourlyAverageResponseTimeByKey(vars["key"], from, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == common.ErrEndpointNotFound {
|
if err == common.ErrEndpointNotFound {
|
||||||
writer.WriteHeader(http.StatusNotFound)
|
http.Error(writer, err.Error(), http.StatusNotFound)
|
||||||
} else if err == common.ErrInvalidTimeRange {
|
} else if err == common.ErrInvalidTimeRange {
|
||||||
writer.WriteHeader(http.StatusBadRequest)
|
http.Error(writer, err.Error(), http.StatusBadRequest)
|
||||||
} else {
|
} else {
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
_, _ = writer.Write([]byte(err.Error()))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(hourlyAverageResponseTime) == 0 {
|
if len(hourlyAverageResponseTime) == 0 {
|
||||||
writer.WriteHeader(http.StatusNoContent)
|
http.Error(writer, "", http.StatusNoContent)
|
||||||
_, _ = writer.Write(nil)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
series := chart.TimeSeries{
|
series := chart.TimeSeries{
|
||||||
|
Loading…
Reference in New Issue
Block a user