Ignore:
Timestamp:
2021-03-14T17:42:43+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #20596 - better error message when GeoAPI fails. Ask to report issues to https://github.com/etalab/geo.data.gouv.fr, https://twitter.com/geodatagouv, geo@…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/api/CadastreAPI.java

    r34711 r35727  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.fr.cadastre.api;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.io.IOException;
     
    1719import org.openstreetmap.josm.io.OsmApiException;
    1820import org.openstreetmap.josm.tools.HttpClient;
     21import org.openstreetmap.josm.tools.HttpClient.Response;
    1922import org.openstreetmap.josm.tools.JosmRuntimeException;
    2023
     
    2427public final class CadastreAPI {
    2528
    26     private static final String API_ENDPOINT = "https://sandbox.geo.api.gouv.fr/cadastre/";
     29    private static final String API_ENDPOINT = "https://sandbox.geo.api.gouv.fr/cadastre";
    2730
    2831    private CadastreAPI() {
     
    5356                Double.toString(minlon), Double.toString(minlat), Double.toString(maxlon), Double.toString(maxlat)));
    5457        try {
    55             JsonStructure json = Json.createReader(new StringReader(HttpClient.create(url).connect().fetchContent())).read();
     58            Response response = HttpClient.create(url).connect();
     59            if (response.getResponseCode() >= 400) {
     60                throw new IOException(
     61                        tr("Cadastre GeoAPI returned HTTP error {0}. This is not a JOSM bug.\nPlease report the issue to {1}, {2} or {3}",
     62                        response.getResponseCode(), "https://github.com/etalab/geo.data.gouv.fr/issues", "https://twitter.com/geodatagouv",
     63                        "geo@data.gouv.fr"));
     64            }
     65            JsonStructure json = Json.createReader(new StringReader(response.fetchContent())).read();
    5666            if (json instanceof JsonArray) {
    5767                return json.asJsonArray().stream().map(x -> x.asJsonObject().getString("id")).collect(Collectors.toSet());
Note: See TracChangeset for help on using the changeset viewer.