Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!