Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda