banool/recreation-gov-campsite-checker

Return Value When Lookup Fails Is The Same As Return Value When No Campsites Found

Opened this issue · 2 comments

About 5% of the time the lookup fails, due to the website being busy and returns an error. If I recall correctly, this throws an exception and the return value is also 1. Since the output of the program clearly lists success or failure, it is not necessary to return 1 if no campsites are found and 0 if campsites are found. I changed it to always return 0 and if it fails and throws an exception, i have a shell script that tries a second time after a few seconds. Otherwise as busy times, it will not find campsites.

This is so I know whether to run the notifier or not. In reality this is real janky and it should only return non zero when it actually fails, you're totally right, and in other cases returns json or something. I'd accept a PR to change this.

It would be a nice change to have different return codes for the different scenarios - it's common for 0 to indicate success, 1 might be more of an "expected" failure (like not finding sites), and then >1 for various unexpected errors (like network failures, or illegal arguments, things like that). I'm currently setting this up in a cronjob but aiming to monitor the cron's health with something like cronitor.io, and it makes it difficult to distinguish between the expected and unexpected cases.