NEWS
JavaScript - http request Fehler abfangen
-
Hallo ich bräuchte mal Eure Hilfe:
Ich frage per hhtp-request einzelne Werte eines Servers ab. Funktioniert auch meistens.
(In einer async function mit await). Dabei bekomme ich aber ETIMEDOUT Fehler zurück. Diese fange ich ab und versuche es nochmal. Dann noch ein drittes Mal. Da parallel (asynchron) aber andere requests laufen, macht der Server dann ab und zu zu, d.h. antwortet mit ETIMEDOUT. Das ist nicht ideal und nicht zu 100% die Lösung.Wer kann mir helfen, wie ich das richtig mache? (Eine Liste von hhtp-requests abarbeiten und Fehler abfangen).
-
poste mal den script-teil, dann kann man dir vielleicht leichter helfen
-
hier der Script-Teil
// im array list stehen die Abfrage-Werte .... async function main(list) { let i = 0; for (i = 0; i < list.length; i++) { if (list[i] !== '') { const url = ipadress + '/'+list[i]) ; try { const body = await get(url); ........ } catch(error) { try { const body = await get(url); ...... } catch(error) { try { const body = await get(url); ...... } catch(error){ console.log('http Fehler: ' + url + ' ---> ' + error); } } } } } } function get(url) { return new Promise(function(resolve,reject) { const options = { url: url, method: 'GET', timeout: 5000 }; request(options, function(error,response,body) {if (error) return reject(error); resolve(body);}); }); }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login