Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Im trying to catch exception in OpenLayers using vector layers in conjunction with http protocol, its possible to intercept an ServiceException from geoserver ... it will be great to display some kinda of error message when it happens.

here my snippet:

var layer = new OpenLayers.Layer.Vector("Foo", {
  projection: new OpenLayers.Projection("EPSG:4326"),
  strategies: [new OpenLayers.Strategy.Fixed()],
  reportError: true,
  protocol: new OpenLayers.Protocol.HTTP({
    url: "/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ns:foo&outputFormat=json&viewparams=foo:var;",
    format: new OpenLayers.Format.GeoJSON()
  })
});

ideas ??

thks !

share|improve this question
add comment

2 Answers

Try using the callback and see what it returns:

var layer = new OpenLayers.Layer.Vector("Foo", {
  projection: new OpenLayers.Projection("EPSG:4326"),
  strategies: [new OpenLayers.Strategy.Fixed()],
  reportError: true,
  protocol: new OpenLayers.Protocol.HTTP({
    url: "/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ns:foo&outputFormat=json&viewparams=foo:var;",
    format: new OpenLayers.Format.GeoJSON()
    callback: function(e) { 
       alert('Did at least something happen?'); 
       console.log(e);
    }
  })
});
share|improve this answer
    
This is a good lead. You will not be be able to catch a Service Exception on the client side, unless GeoServer informs the client of a ServiceException. If it does you're in business, you can handle the exception appropriately. –  OptimizePrime Jun 22 '12 at 18:53
    
good advice CaptDragon ... i try "callback" method previously but never executed ... HTTP protocol error ?? –  outaTiME Jun 23 '12 at 0:11
    
OptimizePrime, ServiceException was an example ... i want to catch error codes to ... like 404 or whatever ... –  outaTiME Jun 23 '12 at 0:13
    
What does firebug say? You can also use Fiddler2. Do you see and HTTP WFS request being made ajax style? –  CaptDragon Jun 25 '12 at 14:43
add comment

the issue comes from "OpenLayers.Strategy.Fixed" this strategy overrides callback method, soo ... i create a fork from openlayers and implements event listeners for strategies ... take a look:

var fixed = new OpenLayers.Strategy.Fixed();

fixed.events.register("fail", this, function (response) {
  console.info("Fail.")
});

var layer = new OpenLayers.Layer.Vector("Foo", {
  projection: new OpenLayers.Projection("EPSG:4326"),
  strategies: [fixed],
  protocol: new OpenLayers.Protocol.HTTP({
    url: "/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ns:foo&outputFormat=json&viewparams=foo:var;",
    format: new OpenLayers.Format.GeoJSON()
  })
});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.