enhance error handling
This commit is contained in:
parent
f74d6fd667
commit
b3e93f8478
|
|
@ -38,7 +38,7 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
|
|||
property, ok := request.URL.Query()["property"]
|
||||
if !ok || len(property[0]) < 1 {
|
||||
log.Println("Url Param 'property' is missing")
|
||||
fmt.Fprintf(response, "{ \"msg\": \"property must be specified in URL\" }")
|
||||
fmt.Fprintf(response, "{ \"msg\": \"error: property must be specified in URL\" }")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
|
|||
|
||||
if !ok || len(deveui[0]) < 1 {
|
||||
log.Println("Url Param 'deveui' is missing")
|
||||
fmt.Fprintf(response, "{ \"msg\": \"deveui must be specified in URL\" }")
|
||||
fmt.Fprintf(response, "{ \"msg\": \"error: deveui must be specified in URL\" }")
|
||||
return
|
||||
}
|
||||
// Query()["deveui"] will return an array of items,
|
||||
|
|
@ -55,7 +55,7 @@ func metricsHandler(response http.ResponseWriter, request *http.Request) {
|
|||
|
||||
if !(Contains(getMyDevs(name), mydeveui)) {
|
||||
log.Println("specified 'deveui' does not belong to this user")
|
||||
fmt.Fprintf(response, "{ \"msg\": \"specified deveui does not belong to this user\" }")
|
||||
fmt.Fprintf(response, "{ \"msg\": \"error: specified deveui does not belong to this user\" }")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +334,7 @@ func getLastMetrics(deveui string) OneMetric {
|
|||
res.Weight = value
|
||||
i, err := strconv.Atoi(value)
|
||||
if err == nil {
|
||||
res.Weight_kg = fmt.Sprintf("%.2f", float64(i)/1000.0)
|
||||
res.Weight_kg = fmt.Sprintf("%.3f", float64(i)/1000.0)
|
||||
} else {
|
||||
res.Weight_kg = "ERR"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
maxfunc = function(max) { return max + 2000 }
|
||||
labels = {
|
||||
formatter: function(val, index) {
|
||||
return (val / 1000.0).toFixed(2);
|
||||
return (val / 1000.0).toFixed(3);
|
||||
}
|
||||
};
|
||||
} else if (property==="h") {
|
||||
|
|
@ -212,6 +212,12 @@ function drawGraph(deveui, alias, property, start, stop, create_graph) {
|
|||
<div class="message-body">
|
||||
Abo ist abgelaufen
|
||||
</div>
|
||||
</article>`);
|
||||
} else if (mydata.msg.includes("error:")) {
|
||||
$('#chart').html(`<article class="message is-danger">
|
||||
<div class="message-body">
|
||||
Fehler im Aufruf
|
||||
</div>
|
||||
</article>`);
|
||||
} else {
|
||||
location.reload(true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue