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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…