Performance: Returning different status codes
MEDIUM IMPACT
This affects the server response time and perceived page load speed by the client, impacting how quickly the browser can proceed after receiving the status code.
public ResponseEntity<String> getData() {
Optional<String> data = service.getDataOptional();
return data.map(d -> ResponseEntity.ok(d))
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).body("Not Found"));
}public ResponseEntity<String> getData() {
try {
String data = service.getData();
return new ResponseEntity<>(data, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>("Error", HttpStatus.INTERNAL_SERVER_ERROR);
}
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generic 500 on all errors | N/A (server-side) | N/A | N/A | [X] Bad |
| Specific status codes (404, 200) | N/A (server-side) | N/A | N/A | [OK] Good |