Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
What is the reason for fetch not working even though the response is perfect from Spring Boot?

Giving a fetch request from react js element to fetch the list of all company objects,the response in the dev tools is correct and the request is working fine from SpringBoot Side But still the fetch is not working as its most probably throwing an error

Fetch Code:

    fetch('http://localhost:8088/companies/', {
        mode: 'no-cors'
    })
        .then(res => {
            console.log(res)
            if (res.ok)
                return res.json()
            throw res
        })
        .then(data => {
            console.log(data)
            setCompanies(data)
        })

If I dont use res.ok => it gives error,here it does not give error but when I print data it gives undefined

Spring Boot Controller Code:

@GetMapping("/")
public ResponseEntity<?> findAllCompanies(){
    log.info("Inside findAllCompanies of CompanyController");
    return ResponseEntity.ok(companyService.findAllCompanies());
}

Spring Boot Service Implementation Code:

@Override
public List<CompanyDTO> findAllCompanies() {
    return companyRepository.findAll()
            .stream()
            .map(company -> companyMapper.map(company,CompanyDTO.class))
            .collect(Collectors.toList());
}

Network Layer Correct Output of /companies/ API

Error Thrown in fetch

Any help is appreciated

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda