-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Description
- Detailed Description:
The methodgetStockByIdinOperationControllerreturnsnullwhen no stock is found, which is not an informative response for API consumers. A proper HTTP 404 Not Found should be returned. - How to Solve:
- Use ResponseEntity:
Modify the method to return aResponseEntityso that you can control the HTTP status. - Check for Null:
If the stock isnull, return a 404 response:@GetMapping("/{id}") public ResponseEntity<Stock> getStockById(@PathVariable Long id) { Stock stock = operationService.getStockById(id); return (stock != null) ? ResponseEntity.ok(stock) : ResponseEntity.notFound().build(); }
- Test the Endpoint:
Use tools like Postman or cURL to ensure that a non-existent stock ID returns a 404 status.
- Use ResponseEntity: