Closed DDorch closed 3 years ago
On Monday the server was down and there was an fatal error from curl
.
I'm not sure how to define "Handle web access problems gracefully". Currently, any operation that fails throw an error. For example:
library(Rthingsboard)
url = "http://scada.g-eau.fr"
publicId = "299cedc0-f3e9-11e8-9dbf-cbc1e37c11e3"
tb_api = ThingsboardApi(url = url, publicId = publicId)
publicId = "299cedc0-f3e9-11e8-9dbf-cbc1e37c11e4"
tb_api = ThingsboardApi(url = url, publicId = publicId)
Error in getToken() :
Request failed with status Client error: (401) Unauthorized
url = "http://toto.zzz.fr"
tb_api = ThingsboardApi(url = url, publicId = publicId)
Error in getToken() :
Request failed with status Client error: (404) Not Found
These messages seem appropriate and comprehensible for me because they are the same errors sent by the API.
Referring to https://bookdown.org/rdpeng/RProgDA/error-handling-and-generation.html, "Stopping the execution of your program with stop() should only happen in the event of a catastrophe - meaning only if it is impossible for your program to continue."
In all the errors above, the error is fatal for the followings procedures to run, so the program must be stopped. So I don't think that gracefully catch these errors in order to throw a warning and return a special value like FALSE
is a good idea.
The user should handle these errors with a tryCatch, so I would change the example in this way.
I also tested the case of a non responding server which was the case that happened on Monday:
url = "https://data-preproduction.inrae.fr"
tb_api = ThingsboardApi(url = url, publicId = publicId)
Error in curl::curl_fetch_memory(url, handle = handle) :
Timeout was reached: [data-preproduction.inrae.fr] Connection timed out after 10014 milliseconds
But I have done a check with this example and I get:
v checking examples (11.1s)
Examples with CPU (user + system) or elapsed time > 5s
user system elapsed
ThingsboardApi-class 0.11 0.01 10.1
So this example can't stay in the check if ever the server is not available during check.
Kurt Hornik wrote: