This commit is contained in:
2026-02-19 17:50:14 +00:00
parent da95a64fb7
commit 6f629c53a6
171 changed files with 7281 additions and 1144 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.exception;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class GlobalExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(DialogflowClientException.class)
public ResponseEntity<Map<String, String>> handleDialogflowClientException(
DialogflowClientException ex) {
Map<String, String> error = new HashMap<>();
error.put("error", "Error communicating with Dialogflow");
error.put("message", ex.getMessage());
logger.error("DialogflowClientException: {}", ex.getMessage());
return new ResponseEntity<>(error, HttpStatus.SERVICE_UNAVAILABLE);
}
@ExceptionHandler(GeminiClientException.class)
public ResponseEntity<Map<String, String>> handleGeminiClientException(GeminiClientException ex) {
Map<String, String> error = new HashMap<>();
error.put("error", "Error communicating with Gemini");
error.put("message", ex.getMessage());
logger.error("GeminiClientException: {}", ex.getMessage());
return new ResponseEntity<>(error, HttpStatus.SERVICE_UNAVAILABLE);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<Map<String, String>> handleAllExceptions(Exception ex) {
Map<String, String> error = new HashMap<>();
error.put("error", "Internal Server Error");
error.put("message", ex.getMessage());
logger.error("An unexpected error occurred: {}", ex.getMessage(), ex);
return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
}