1

I am running http server which always returns 504:

const express = require('express')
const app = express()

app.get('/', (req, res) => {
    console.log('I AM HERE');
    res.status(504).send('Not found!!');
})

app.listen(3000, () => console.log('Listening on port 3000!'))

After that, I'm doing request, using got with 5 retries:

const got = require('got');

(async () => {
    try {
        const response = await got('http://localhost:3000/', {retries: 5});
        console.log(response.body);
    } catch (error) {
        console.log(error.response.body);
    }
})();

I'm expecting, that inscription I AM HERE would be logged 5 times, but it logged only once. What is wrong with my code?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Rostislav Shtanko
  • 704
  • 2
  • 9
  • 30
  • 1
    `got()` only retries when there are network errors (e..g failure to reach the server or DNS failure). A 504 status is a successful contact of the server that returns a 504 status and thus does not retry automatically. – jfriend00 Dec 24 '17 at 21:35

1 Answers1

0

The parameter is retry not retries,Here is the working example

try {
    const response = await got('https://example.com', {retry: 2});
    return response.body
 } catch (error) {
    console.log(error.response.body);   
    return error
 }
Ranjithkumar MV
  • 804
  • 8
  • 10