Class ExceptionResponseMapper

java.lang.Object
io.leandev.appfuse.error.ExceptionResponseMapper

public class ExceptionResponseMapper extends Object

異常回應映射器

提供簡化的 API 用於將異常轉換為 RFC 7807 ProblemDetail。 內部使用 ExceptionMappingRegistry 實作。

簡單使用(推薦給一般應用):

ExceptionResponseMapper mapper = new ExceptionResponseMapper();
ProblemDetail problem = mapper.toProblemDetail(exception);

進階使用(需要自定義 Mapper):

ExceptionMappingRegistry registry = new ExceptionMappingRegistry();
registry.register(new CustomExceptionMapper());
ProblemDetail problem = registry.map(exception);
See Also:
  • Constructor Details

  • Method Details

    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(Exception ex)
      將異常轉換為 ProblemDetail (RFC 7807)
      Parameters:
      ex - 異常
      Returns:
      ProblemDetail
    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(org.springframework.transaction.TransactionSystemException ex)
      將 TransactionSystemException 轉換為 ProblemDetail
      Parameters:
      ex - Spring Transaction 異常
      Returns:
      ProblemDetail
    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(jakarta.validation.ValidationException ex)
      將 ValidationException 轉換為 ProblemDetail
      Parameters:
      ex - Jakarta Validation 異常
      Returns:
      ProblemDetail
    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(org.springframework.dao.DataAccessException ex)
      將 DataAccessException 轉換為 ProblemDetail
      Parameters:
      ex - Spring Data 異常
      Returns:
      ProblemDetail
    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(org.springframework.http.converter.HttpMessageConversionException ex)
      將 HttpMessageConversionException 轉換為 ProblemDetail
      Parameters:
      ex - Spring Web 訊息轉換異常
      Returns:
      ProblemDetail
    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(tools.jackson.databind.exc.InvalidFormatException ex)
      將 InvalidFormatException 轉換為 ProblemDetail
      Parameters:
      ex - Jackson 格式化異常
      Returns:
      ProblemDetail
    • toProblemDetail

      public org.springframework.http.ProblemDetail toProblemDetail(ApplicationException ex)
      將 ApplicationException 轉換為 ProblemDetail
      Parameters:
      ex - AppFuse 應用異常
      Returns:
      ProblemDetail
    • getRegistry

      public ExceptionMappingRegistry getRegistry()
      取得底層的 Registry,允許註冊自定義 Mapper
      Returns:
      ExceptionMappingRegistry