Commit 133da3ab authored by Phil Höfer's avatar Phil Höfer
Browse files

Improve search retry procedure

parent 7fbe804f
const TRIES = 3;
const TRYDELAYINCRMS = 1000;
function loadXMLDoc(filename)
{
var xhttp = new XMLHttpRequest();
......@@ -25,19 +28,20 @@ function render(err, content)
/**
* Delivers OpenSearch responseXML to callback for the given query.
*/
function search(query,focus,callback, tries) {
function search(query,focus,callback, trycount) {
query = query || "eingabe=";
focus = focus || "focus=web";
let doc;
tries = tries || 3;
trycount = trycount || 0;
try {
doc = loadXMLDoc("https://metager3.de/meta/meta.ger3?"+focus+"&"+query+"&encoding=utf8&out=atom10&appversion=3.0.0");
callback(null, doc);
} catch (e) {
if(--tries) {
console.log("search error, tries left: "+tries);
search(query, focus, callback, tries);
if(++trycount < TRIES) {
console.log("search error, tries left: "+ (TRIES - trycount) );
setTimeout(search, trycount * TRYDELAYINCRMS, query, focus, callback, trycount);
} else {
console.log("search failed");
callback(e);
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment