leaflet-gpx icon indicating copy to clipboard operation
leaflet-gpx copied to clipboard

Error handling for 404 (e.g.)

Open tudacs opened this issue 2 years ago • 1 comments

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 for 206 Partial, e.g., given I'm not that familiar with how XMLHttpRequest is designed regarding this.

tudacs avatar Jan 15 '22 13:01 tudacs

Implementation for the both mentioned ideas can be found here:

tudacs avatar Jan 15 '22 13:01 tudacs