question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retry instead of Fail/Pass on non-200 Status Codes

See original GitHub issue

Is this a Feature or Bug?

Feature

Current behavior:

failOnStatusCode: false will silently swallow errors and skip the test on a per visit() basis.

Desired behavior:

While the current behavior is a valid use case, our use case is that non-200 status codes are sometimes expected (because of how the app is deployed for testing internally) and instead we would like the ability to retry instead of swallow, skip and continue.

So maybe a retryOnStatusCode: true or something (or maybe instead of a Boolean it could take an Integer for number of retries).

cc, @ValerieThoma

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brian-manncommented, Mar 26, 2018

I see… I think it’s debatable whether we make cy.visit retry on status code errors. I can totally see us doing it for network related events (because these things naturally happen), but if your server actually responds its hard for me to imagine retrying by default is a good idea.

For instance, a visit is not idempotent and there could be side effects of retrying. A server may decide to respond appropriately and do things like set cookies if it wanted to. Retrying again would then potentially cause a different thing to happen on the next request…

I’m leaning towards creating natural retryability only for network errors. For application errors (such as the one you’re experiencing) I believe the easiest thing is to handle them yourself by creating a recursive function. Something like this should work…

Disclaimer: I am writing this code right now, it may not work but hopefully in theory you should understand what it’s doing.

const is500Re = /^5/

const visitWhenStable = (url, options) => {
  function req () {
    return cy.request(url, { failOnStatusCode: false ))
    .then((resp) => {
      if (is500Re.test(resp.status)) {
        return req()      
      }
  
      return cy.visit(url, options)
    })
  }
  
  // kickoff
  return req()
}
0reactions
tizmagikcommented, Mar 27, 2018

Yes, that’s fair and makes sense, thanks @brian-mann – will give that a shot on our end and post back if there’s any further issues. Right now we’re planning on “overwriting” the cy.visit() command to transparently check for 200 first so that we don’t have to change our test code much if at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to set RetryPolicy in spring-retry based on ...
e.g. I want to retry on HttpServerErrorException with HttpStatus.INTERNAL_SERVER_ERROR status code, which is 503. Therefore it should ignore all other error ...
Read more >
Retry policy for non-200 HTTP status response
As far as I can see in our tests, when a non-200 HTTP status is returned, monday retries every 30 secs for 10...
Read more >
List of HTTP status codes - Wikipedia
This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are issued by a server in response to a...
Read more >
HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
Can I make cURL fail with an exitCode different than 0 if the ...
How about if I want to output the response on failure (non 200), but return a non 0 status code from the script?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found