Commit 35ab3b87 by Rubén Ramírez

feat: [GlobalExceptionHandler]: Añadidos comentarios para entender la existencia…

feat: [GlobalExceptionHandler]: Añadidos comentarios para entender la existencia de GlobalExceptionHandler
parent b4820404
package com.ujaen.tfg.mangaffinity.excepciones; package com.ujaen.tfg.mangaffinity.excepciones;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* Clase dedicada a trabajar con las excepciones que después se toman en el frontend
* para el registro de usuario.g
*/
@RestControllerAdvice @RestControllerAdvice
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(UsuarioYaRegistrado.class) @ExceptionHandler(UsuarioYaRegistrado.class)
public ResponseEntity<String> handleUsuarioYaRegistrado(UsuarioYaRegistrado ex) { public ResponseEntity<String> handleUsuarioYaRegistrado(UsuarioYaRegistrado ex) {
logger.warn("GlobalExceptionHandler capturó UsuarioYaRegistrado: {}", ex.getMessage());
return ResponseEntity.status(HttpStatus.CONFLICT) return ResponseEntity.status(HttpStatus.CONFLICT)
.contentType(org.springframework.http.MediaType.TEXT_PLAIN) .contentType(org.springframework.http.MediaType.TEXT_PLAIN)
.body("correo"); .body("correo");
...@@ -22,7 +21,6 @@ public class GlobalExceptionHandler { ...@@ -22,7 +21,6 @@ public class GlobalExceptionHandler {
@ExceptionHandler(NombreUsuarioYaRegistrado.class) @ExceptionHandler(NombreUsuarioYaRegistrado.class)
public ResponseEntity<String> handleNombreUsuarioYaRegistrado(NombreUsuarioYaRegistrado ex) { public ResponseEntity<String> handleNombreUsuarioYaRegistrado(NombreUsuarioYaRegistrado ex) {
logger.warn("GlobalExceptionHandler capturó NombreUsuarioYaRegistrado: {}", ex.getMessage());
return ResponseEntity.status(HttpStatus.CONFLICT) return ResponseEntity.status(HttpStatus.CONFLICT)
.contentType(org.springframework.http.MediaType.TEXT_PLAIN) .contentType(org.springframework.http.MediaType.TEXT_PLAIN)
.body("nombre de usuario"); .body("nombre de usuario");
...@@ -30,7 +28,6 @@ public class GlobalExceptionHandler { ...@@ -30,7 +28,6 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public ResponseEntity<String> handleGenericException(Exception ex) { public ResponseEntity<String> handleGenericException(Exception ex) {
logger.error("Excepción no controlada en GlobalExceptionHandler: {}", ex.getMessage(), ex);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.contentType(org.springframework.http.MediaType.TEXT_PLAIN) .contentType(org.springframework.http.MediaType.TEXT_PLAIN)
.body("Error inesperado."); .body("Error inesperado.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment