Ajout, corrections et modifications de tests unitaires pour la partie infrastructure.web.controller.
Amélioration de la couverture de test
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.context.request.async.AsyncRequestNotUsableException;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -71,6 +72,21 @@ public class GlobalExceptionHandler {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Statut HTTP explicitement choisi par un controller via {@link ResponseStatusException}
|
||||
* (ex: {@code NotebookController} -> 404 si notebook introuvable, 502 si Brain injoignable).
|
||||
* <p>
|
||||
* SANS ce handler, le fallback {@code @ExceptionHandler(Throwable.class)} ci-dessous
|
||||
* interceptait ces exceptions et renvoyait 500 — ecrasant le statut voulu (le
|
||||
* resolver natif de Spring est court-circuite des qu'un advice gere Throwable).
|
||||
*/
|
||||
@ExceptionHandler(ResponseStatusException.class)
|
||||
public ResponseEntity<Map<String, String>> handleResponseStatus(ResponseStatusException ex) {
|
||||
String reason = ex.getReason();
|
||||
return ResponseEntity.status(ex.getStatusCode())
|
||||
.body(Map.of("error", reason != null ? reason : ex.getStatusCode().toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Client HTTP parti pendant une reponse asynchrone (SSE) : le navigateur a ferme
|
||||
* la connexion (onglet ferme, proxy coupe...), la reponse n'est plus utilisable.
|
||||
|
||||
Reference in New Issue
Block a user