ncss-tech / soilDB

soilDB: Simplified Access to National Cooperative Soil Survey Databases
http://ncss-tech.github.io/soilDB/
GNU General Public License v3.0
81 stars 20 forks source link

SDA_query: handle API failures with more grace #351

Closed brownag closed 4 months ago

brownag commented 4 months ago

Soil Data Access goes down intermittently for maintenance or due to crashes of the server. This PR adds handling to check the response content type for SDA_query() POST requests.

Essentially, any content type other than JSON (data) or XML (error message) indicates the service is temporarily down. When the service is down it does not produce normal response that can be used by either the data or error parsing approach.

As an additional item in this PR I will develop a wrapper function that can catch errors and print an informative message for the user--there are several instances of functions that use SDA_query() but do not handle the possibility of try-error response--which can result in some unusual error messages in lieu of expected result. We will distinguish this "service is down" case from other possible issues (say, incorrectly formatted arguments that affect the query used)

dylanbeaudette commented 4 months ago

Thanks. The additional error handling will help downstream functions fail gracefully. I never expected that SDA would be "down" so frequently.