Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors when requesting API #29913

Open
LuizVithor opened this issue Jul 23, 2024 · 3 comments
Open

errors when requesting API #29913

LuizVithor opened this issue Jul 23, 2024 · 3 comments
Labels
stage: needs information Not enough info to reproduce the issue type: bug

Comments

@LuizVithor
Copy link

LuizVithor commented Jul 23, 2024

Current behavior

I'm making requests in an api but when I'm using Cypress it returns error 400 or net::ERR_EMPTY_RESPONSE on a specific route with a specific method, but when I access it in a normal browser, other than Cypress, it works normally.

Literally the same request but in Cypress it gives an error...

in some cases it gives the error "net::ERR_EMPTY_RESPONSE" and in others it gives a 400 error bringing an api error but the same request in the normal browser works.

My cypress.config.ts:

import dotenv from 'dotenv';
dotenv.config();
import { defineConfig } from "cypress";

export default defineConfig({
  e2e: {
    baseUrl: process.env["NEXT_PUBLIC_URL_CYPRESS"],
    setupNodeEvents(_on, config) {
      config.env = {
        ...process.env,
        ...config.env
      }
      return config
    },
    reporter: 'mochawesome',
    reporterOptions: {
      charts: true,
      json: true,
      reportsDir: 'reports/your-reports-folder',
      overwrite: true
    },
    chromeWebSecurity: false,
    experimentalModifyObstructiveThirdPartyCode: false,
    modifyObstructiveCode: false
  },
  projectId: "MYPROJECTID",
  chromeWebSecurity: false,
  experimentalModifyObstructiveThirdPartyCode: false
});

I noticed that most, if not all requests that give an error, in the normal browser return 204 no content

image
image
image
image
image
image

Desired behavior

it should have just been successful and the interception returned a common request with statuscode 204, as 204 is not an http error

Test code to reproduce

I'm not going to have a test code, but basically I was simulating a website and one of the requests I needed to make, returned 204, and I realized that all that returned 204 gave an error

Cypress Version

13.13.1

Node version

v20.12.1

Operating System

windows 11

Debug Logs

No response

Other

No response

@D0d0d
Copy link

D0d0d commented Jul 25, 2024

I had similar problem those weeks and in the end it was about queuing cy commands since they are async.
I moved my wait in "cy.request.toTrigger.then" block and specified which exactly response to wait.

cy.request().then(res=>{
....
})

If it suits your case, I found where to look for my conditions here:
Docs: cy.request(Yields)

@LuizVithor
Copy link
Author

So, from what I understand, the error is only in 204 requests, instead of it returning the status code "204" in the interception, it returns an error, for now I'm aligning it with my back end so it doesn't send 204 anymore, but this It bothers me because 204 is not an error, but a success

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue type: bug labels Jul 26, 2024
@jennifer-shehane
Copy link
Member

We'd need a way to test this ourselves to narrow it down. It does seem strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue type: bug
Projects
None yet
Development

No branches or pull requests

3 participants