leaflet-gpx
leaflet-gpx copied to clipboard
Error handling for 404 (e.g.)
Recently I tried handling '404 Not found'-errors while loading GPX-data by the 'error'-event, as the README reads like this should be the way to handle it.
This failed, as the corresponding parts of the code (_load_xml
) only call the event-firing callback (in _parse
) if the return code equals 200.
As a rather quick'n'dirty workaround, I added 'error'-event-firing in _load_xml
for req.status == 404
for my use-case and would like to request comments or ideas how to handle this (more) properly.
Ideas so far:
- discard
req.status == 200
-condition. Should/Would keep a single point of firing 'error', but fails currently, as_parse_xml_data
expects a proper (gpx-)xml-document. Maybe add a try-catch block around calling_parse_xml_data
? - add a
else
-branch and fire 'error' in_load_xml
. From my point of view this might be a problem for206 Partial
, e.g., given I'm not that familiar with how XMLHttpRequest is designed regarding this.
Implementation for the both mentioned ideas can be found here: