3 /***************************************************************************
5 * Error handling functions
8 function chksql($oSql, $sMsg = "Database request failed")
10 if (!PEAR::isError($oSql)) return $oSql;
12 header('HTTP/1.0 500 Internal Server Error');
13 header('Content-type: text/html; charset=utf-8');
15 $sSqlError = $oSql->getMessage();
19 <head><title>Internal Server Error</title></head>
21 <h1>Internal Server Error</h1>
22 <p>Nominatim has encountered an internal error while accessing the database.
23 This may happen because the database is broken or because of a bug in
24 the software. If you think it is a bug, feel free to report
25 it over on <a href="https://github.com/twain47/Nominatim/issues">
26 Github</a>. Please include the URL that caused the problem and the
27 complete error details below.</p>
28 <p><b>Message:</b> $sMsg</p>
29 <p><b>SQL Error:</b> $sSqlError</p>
30 <p><b>Details:</b> <pre>
39 echo "<pre>\n".$oSql->getUserInfo()."</pre>";
42 echo "</pre></p></body></head></html>";
46 function failInternalError($sError, $sSQL = false, $vDumpVar = false)
48 header('HTTP/1.0 500 Internal Server Error');
49 header('Content-type: text/html; charset=utf-8');
50 echo "<html><body><h1>Internal Server Error</h1>";
51 echo '<p>Nominatim has encountered an internal error while processing your request. This is most likely because of a bug in the software.</p>';
52 echo "<p><b>Details:</b> ".$sError,"</p>";
53 echo '<p>Feel free to file an issue on <a href="https://github.com/twain47/Nominatim/issues">Github</a>. Please include the error message above and the URL you used.</p>';
56 echo "<hr><h2>Debugging Information</h2><br>";
59 echo "<h3>SQL query</h3><code>".$sSQL."</code>";
63 echo "<h3>Result</h3> <code>";
68 echo "\n</body></html>\n";
73 function userError($sError)
75 header('HTTP/1.0 400 Bad Request');
76 header('Content-type: text/html; charset=utf-8');
77 echo "<html><body><h1>Bad Request</h1>";
78 echo '<p>Nominatim has encountered an error with your request.</p>';
79 echo "<p><b>Details:</b> ".$sError,"</p>";
80 echo '<p>If you feel this error is incorrect feel file an issue on <a href="https://github.com/twain47/Nominatim/issues">Github</a>. Please include the error message above and the URL you used.</p>';
81 echo "\n</body></html>\n";
86 /***************************************************************************
88 * Functions for parsing URL parameters
92 function getParamBool($sName, $bDefault=false)
94 if (!isset($_GET[$sName])) return $bDefault;
96 return (bool) $_GET[$sName];
99 function getParamInt($sName, $bDefault=false)
101 if (!isset($_GET[$sName])) return $bDefault;
103 if (!preg_match('/^[+-]?[0-9]+$/', $_GET[$sName]))
105 userError("Integer number expected for parameter '$sName'");
108 return (int) $_GET[$sName];
111 function getParamFloat($sName, $bDefault=false)
113 if (!isset($_GET[$sName])) return $bDefault;
115 if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET[$sName]))
117 userError("Floating-point number expected for parameter '$sName'");
120 return (float) $_GET[$sName];
123 function getParamString($sName, $bDefault=false)
125 if (!isset($_GET[$sName])) return $bDefault;
127 return $_GET[$sName];
130 function getParamSet($sName, $aValues, $sDefault=false)
132 if (!isset($_GET[$sName])) return $sDefault;
134 if (!in_array($_GET[$sName], $aValues))
136 userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
139 return $_GET[$sName];