Skip to content

Commit a86708b

Browse files
committed
Handle 404 from CHS tide API without crashing or nuking stations
The CHS API sometimes returns 404 for station tide data requests. Previously this raised an unhandled Mechanize::ResponseCodeError through the entire Sinatra stack. Now we catch 404 specifically, log a warning, and return nil — keeping the station in the list so it can be retried on subsequent requests.
1 parent 211a6a0 commit a86708b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

clients/chs_tides.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ def tide_data_for(station, around)
4848

4949
logger.info "getting tide data from #{url}"
5050

51-
return nil unless json = get_url(url)
51+
begin
52+
return nil unless json = get_url(url)
53+
rescue Mechanize::ResponseCodeError => e
54+
if e.response_code == "404"
55+
logger.warn "404 for station #{station.id}, skipping (may be temporary)"
56+
return nil
57+
end
58+
raise
59+
end
5260

5361
logger.debug "parsing tide predictions for #{station.id} from API #{API_URL}"
5462
data = JSON.parse(json) rescue []

0 commit comments

Comments
 (0)