Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

javascript - Leaflet WMS - how do I get the HTTP status code from an error?

I am working on a React app using Leaflet 1.6.0 with Leaflet.nontiledlayer to display images from a WMS service. This WMS service requires authentication, and after some period of time, my session will expire, and all calls to the WMS service will fail with a HTTP 401 unauthorized status code.

In my error handling code, I would like to detect this HTTP 401 code, so that I can redirect the user back to the login page. But when I debug my error handling code, I do not see a field that contains the HTTP status code from the response. How can I check the HTTP status code when a WMS request fails?

I have thoroughly inspected both the error and target objects, and I do not see any field that corresponds to the HTTP status code.

My map layer is initialized as follows:

 let mapDefault = L.nonTiledLayer.wms(appconfig.baseurl + "/OGC/WMS", {
      ...wmsOptions,
      ...{ layers: "DEFAULT", name: "Default" }
    });

My error handling function:

    const errorhandler = function (error, tile) {
      const { target, sourceTarget } = error;
      if (
        target &&
        target.wmsParams &&
        target.wmsParams.name &&
        (target.wmsParams.name === "Default")
      ) {
          this.props.dispatch(
            crewAlertActions.error(`Error in loading base map layer`)
          );
        }
    };
    mapDefault.on("error", errorhandler.bind(this));
question from:https://stackoverflow.com/questions/66050239/leaflet-wms-how-do-i-get-the-http-status-code-from-an-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...