Ignore:
Timestamp:
2018-12-10T23:39:08+01:00 (5 years ago)
Author:
Don-vip
Message:

see #16073 - rework error handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r14549 r14550  
    225225     */
    226226    protected static ImageryInfo getWMSLayerInfo(ImageryInfo info) throws IOException, WMSGetCapabilitiesException {
    227         return getWMSLayerInfo(info, AddImageryLayerAction::askToSelectLayers);
     227        try {
     228            return getWMSLayerInfo(info, AddImageryLayerAction::askToSelectLayers);
     229        } catch (MalformedURLException ex) {
     230            handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
     231        } catch (IOException ex) {
     232            handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
     233        } catch (WMSGetCapabilitiesException ex) {
     234            handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
     235                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
     236        }
     237        return null;
    228238    }
    229239
     
    240250    public static ImageryInfo getWMSLayerInfo(ImageryInfo info, Function<WMSImagery, LayerSelection> choice)
    241251            throws IOException, WMSGetCapabilitiesException {
    242         try {
    243             CheckParameterUtil.ensureThat(ImageryType.WMS_ENDPOINT == info.getImageryType(), "wms_endpoint imagery type expected");
    244             final WMSImagery wms = new WMSImagery(info.getUrl(), info.getCustomHttpHeaders());
    245             LayerSelection selection = choice.apply(wms);
    246             if (selection == null) {
    247                 return null;
    248             }
    249 
    250             final String url = wms.buildGetMapUrl(
    251                     selection.layers.stream().map(LayerDetails::getName).collect(Collectors.toList()),
    252                     (List<String>) null,
    253                     selection.format,
    254                     selection.transparent
    255                     );
    256 
    257             String selectedLayers = selection.layers.stream()
    258                     .map(LayerDetails::getName)
    259                     .collect(Collectors.joining(", "));
    260             // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different
    261             ImageryInfo ret = new ImageryInfo(info);
    262             ret.setUrl(url);
    263             ret.setImageryType(ImageryType.WMS);
    264             ret.setName(info.getName() + selectedLayers);
    265             ret.setServerProjections(wms.getServerProjections(selection.layers));
    266             return ret;
    267         } catch (MalformedURLException ex) {
    268             handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
    269         } catch (IOException ex) {
    270             handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
    271         } catch (WMSGetCapabilitiesException ex) {
    272             handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
    273                     "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
    274         }
    275         return null;
     252        CheckParameterUtil.ensureThat(ImageryType.WMS_ENDPOINT == info.getImageryType(), "wms_endpoint imagery type expected");
     253        final WMSImagery wms = new WMSImagery(info.getUrl(), info.getCustomHttpHeaders());
     254        LayerSelection selection = choice.apply(wms);
     255        if (selection == null) {
     256            return null;
     257        }
     258
     259        final String url = wms.buildGetMapUrl(
     260                selection.layers.stream().map(LayerDetails::getName).collect(Collectors.toList()),
     261                (List<String>) null,
     262                selection.format,
     263                selection.transparent
     264                );
     265
     266        String selectedLayers = selection.layers.stream()
     267                .map(LayerDetails::getName)
     268                .collect(Collectors.joining(", "));
     269        // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different
     270        ImageryInfo ret = new ImageryInfo(info);
     271        ret.setUrl(url);
     272        ret.setImageryType(ImageryType.WMS);
     273        ret.setName(info.getName() + selectedLayers);
     274        ret.setServerProjections(wms.getServerProjections(selection.layers));
     275        return ret;
    276276    }
    277277
Note: See TracChangeset for help on using the changeset viewer.