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
Any help is appreciated