Class DifyApiException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.agentscope.core.rag.integration.dify.exception.DifyApiException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DifyAuthException

public class DifyApiException extends RuntimeException
Exception thrown when Dify API returns an error response.

This exception encapsulates error information from Dify API responses, including HTTP status codes, error codes, and error messages.

Common error scenarios:

  • 400 Bad Request: Invalid parameters or malformed request
  • 401 Unauthorized: Invalid or missing API key
  • 403 Forbidden: Insufficient permissions
  • 404 Not Found: Dataset or document not found
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Internal Server Error: Dify service error
See Also:
  • Constructor Details

    • DifyApiException

      public DifyApiException(String message)
      Creates a new DifyApiException with a message.
      Parameters:
      message - the error message
    • DifyApiException

      public DifyApiException(String message, Throwable cause)
      Creates a new DifyApiException with a message and cause.
      Parameters:
      message - the error message
      cause - the underlying cause
    • DifyApiException

      public DifyApiException(int statusCode, String message)
      Creates a new DifyApiException with HTTP status code.
      Parameters:
      statusCode - the HTTP status code
      message - the error message
    • DifyApiException

      public DifyApiException(int statusCode, String errorCode, String message)
      Creates a new DifyApiException with full error details.
      Parameters:
      statusCode - the HTTP status code
      errorCode - the Dify error code
      message - the error message
    • DifyApiException

      public DifyApiException(int statusCode, String errorCode, String message, Throwable cause)
      Creates a new DifyApiException with full error details and cause.
      Parameters:
      statusCode - the HTTP status code
      errorCode - the Dify error code
      message - the error message
      cause - the underlying cause
  • Method Details

    • getStatusCode

      public int getStatusCode()
      Gets the HTTP status code.
      Returns:
      the status code, or -1 if not available
    • getErrorCode

      public String getErrorCode()
      Gets the Dify error code.
      Returns:
      the error code, or null if not available
    • isClientError

      public boolean isClientError()
      Checks if this is a client error (4xx status code).
      Returns:
      true if status code is 4xx
    • isServerError

      public boolean isServerError()
      Checks if this is a server error (5xx status code).
      Returns:
      true if status code is 5xx
    • isRateLimitError

      public boolean isRateLimitError()
      Checks if this is a rate limit error (429 status code).
      Returns:
      true if status code is 429
    • toString

      public String toString()
      Overrides:
      toString in class Throwable