[mapserver-users] Query error messages

Silke Reimer silke@intevation.de
Tue, 10 Sep 2002 09:42:07 +0200


--+g7M9IMkV8truYOl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Sep 09, 2002 at 02:59:52PM +0100, Matthew Hatcher wrote:
> Thanks.
> =20
> Can't believe I missed something that obvious! But I'm now going to make =
it
> a little harder for you all! Assuming that an error occurs and the page is
> diverted to the url specified, is there any way to find out what the error
> was? I presume (haven't checked the code) that MapServer does a simple
> redirect to the page specified, rather than using it as a template, so it
> wouldn't be possible to use a template variable or would it?

If you interested to use a template you can apply the patch which
you find at the end of the mail. Afterwards you can use the keyword
ERROR_TEMPLATE in the Web object to specify a template which should
be used when the query was empty.=20

Please note that the patch was written for mapserver 3.5 and has
been adapted to the mapserver 3.6. So there will appear some warnings
when you apply the patch by the 'patch' command. You can ignore
them.

By the way: It could be interesting to incorporate the patch in the
current mapserver code.=20

Silke

> =20
> Matt.
> =20
> -----Original Message-----
> From: Marc Jacquin [mailto:jacquin@geosys-inc.com]
> Sent: 09 September 2002 13:05
> To: Matthew Hatcher; mapserver-users@lists.gis.umn.edu
> Subject: RE: [mapserver-users] Query error messages
>=20
>=20
> Matt,
> =20
> Check the ERROR [url] keyword in the Web object.
> =20
> Marc
> =20

--=20
Silke Reimer

Intevation GmbH                      http://intevation.de/
FreeGIS                                http://freegis.org/


----------- here comes the patch --------------------------

diff -uNr mapserver/map.h mapserver-3.5-dev/map.h
--- mapserver/map.h	Fri Oct  5 05:44:57 2001
+++ mapserver-3.5-dev/map.h	Wed Oct 10 11:20:06 2001
@@ -326,6 +326,8 @@
 #endif
   char *header, *footer;
   char *empty, *error; /* error handling */
+  char *empty_template; /* show error message with a template */
+
   rectObj extent; /* clipping extent */
   double minscale, maxscale;
   char *mintemplate, *maxtemplate;
diff -uNr mapserver/mapfile.c mapserver-3.5-dev/mapfile.c
--- mapserver/mapfile.c	Wed Oct  3 05:33:13 2001
+++ mapserver-3.5-dev/mapfile.c	Wed Oct 10 11:33:30 2001
@@ -2791,7 +2791,7 @@
   web->extent.minx =3D web->extent.miny =3D web->extent.maxx =3D web->exte=
nt.maxy =3D -1.0;
   web->template =3D NULL;
   web->header =3D web->footer =3D NULL;
-  web->error =3D  web->empty =3D NULL;
+  web->error =3D  web->empty =3D web->empty_template =3D NULL;
   web->mintemplate =3D web->maxtemplate =3D NULL;
   web->minscale =3D web->maxscale =3D -1;
   web->log =3D NULL;
@@ -2807,6 +2807,7 @@
   msFree(web->footer);
   msFree(web->error);
   msFree(web->empty);
+  msFree(web->empty_template);
   msFree(web->maxtemplate);
   msFree(web->mintemplate);
   msFree(web->log);
@@ -2819,6 +2819,8 @@
 {
   fprintf(stream, "  WEB\n");
   if(web->empty) fprintf(stream, "    EMPTY \"%s\"\n", web->empty);
+  if(web->empty_template) fprintf(stream, "    EMPTY_TEMPLATE \"%s\"\n",
+				  web->empty);
   if(web->error) fprintf(stream, "    ERROR \"%s\"\n", web->error);
   if(web->footer) fprintf(stream, "    FOOTER \"%s\"\n", web->footer);
   if(web->header) fprintf(stream, "    HEADER \"%s\"\n", web->header);
@@ -2841,6 +2841,9 @@
     case(EMPTY):
       if((web->empty =3D getString()) =3D=3D NULL) return(-1);
       break;
+    case(EMPTY_TEMPLATE):
+      if((web->empty_template =3D getString()) =3D=3D NULL) return(-1);
+      break;
     case(EOF):
       msSetError(MS_EOFERR, NULL, "loadWeb()");
       return(-1);
@@ -2904,6 +2904,10 @@
   case(EMPTY):
     msFree(web->empty);
     web->empty =3D strdup(value);
+    break;
+  case(EMPTY_TEMPLATE):
+    if(web->empty_template) msFree(web->empty);
+    web->empty_template =3D strdup(value);
     break;
   case(ERROR):
     msFree(web->error);
diff -uNr mapserver/mapfile.h mapserver-3.5-dev/mapfile.h
--- mapserver/mapfile.h	Fri Sep 21 05:50:42 2001
+++ mapserver-3.5-dev/mapfile.h	Wed Oct 10 11:48:44 2001
@@ -158,4 +158,6 @@
=20
 #define DUMP 1125
=20
+#define EMPTY_TEMPLATE 1130
+
 #endif /* MAPFILE_H */
diff -uNr mapserver/maplexer.l mapserver-3.5-dev/maplexer.l
--- mapserver/maplexer.l	Fri Sep 21 05:50:42 2001
+++ mapserver-3.5-dev/maplexer.l	Wed Oct 10 11:20:06 2001
@@ -110,6 +110,7 @@
 <INITIAL,OBJECT_STRING>data		       { return(DATA); }
 <INITIAL,OBJECT_STRING>dump		       { return(DUMP); }
 <INITIAL,OBJECT_STRING>empty		       { return(EMPTY); }
+<INITIAL,OBJECT_STRING>empty_template	       { return(EMPTY_TEMPLATE); }
 <INITIAL>end			               { return(END); }
 <INITIAL,OBJECT_STRING>error		       { return(ERROR); }
 <INITIAL,OBJECT_STRING>expression              { return(EXPRESSION); }
diff -uNr mapserver/mapserv.c mapserver-3.5-dev/mapserv.c
--- mapserver/mapserv.c	Wed Oct 10 11:49:44 2001
+++ mapserver-3.5-dev/mapserv.c	Wed Oct 10 11:38:48 2001
@@ -83,8 +83,17 @@
     exit(0);
   }
=20
-  if((ms_error->code =3D=3D MS_NOTFOUND) && (msObj->Map->web.empty)) {
-    msRedirect(msObj->Map->web.empty);
+  if((ms_error->code =3D=3D MS_NOTFOUND)
+     && (msObj->Map->web.empty || msObj->Map->web.empty_template)) {
+    if (msObj->Map->web.empty_template) {
+	/* set to mode to something other than QUERY so that writeError
+         * is not called recursively. */
+      msObj->Mode =3D BROWSE;
+      printf("Content-type: text/html%c%c", 10, 10);
+      msReturnPage(msObj, msObj->Map->web.empty_template, BROWSE, NULL);
+    } else {
+      msRedirect(msObj->Map->web.empty);
+    }
   } else {
     if(msObj->Map->web.error) {     =20
       msRedirect(msObj->Map->web.error);

--+g7M9IMkV8truYOl
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9faJP1W4oD4nfjasRAl3CAKCdDHgoqEfR6nmi6IR/ITROH2EtVwCg6Mqm
0BgqSPyG8ktVgxTej/8bbmU=
=bQTH
-----END PGP SIGNATURE-----

--+g7M9IMkV8truYOl--