Class GraphException

java.lang.Object
java.lang.Throwable
java.lang.Exception
com.independentsoft.graph.GraphException
All Implemented Interfaces:
Serializable

public class GraphException extends Exception
Exception thrown when Microsoft Graph API requests fail.

This exception captures detailed error information from the Microsoft Graph API, including error codes, messages, request IDs, and timestamps. It parses both standard Graph API error responses and OAuth authentication error responses.

The exception provides access to:

  • Error code - The Graph API error code (e.g., "InvalidAuthenticationToken")
  • Error message - Human-readable description of the error
  • Request ID - Unique identifier for troubleshooting with Microsoft support
  • Date/Timestamp - When the error occurred
  • Error details - Additional error information if available
  • Request URI/Body - The request that caused the error for debugging
Since:
1.0
See Also:
Microsoft Graph error responses, Serialized Form
  • Constructor Details

    • GraphException

      public GraphException(String message, Throwable cause, String requestUri, String requestBody)
      Constructs a GraphException with a message and underlying cause.
      Parameters:
      message - The error message
      cause - The underlying exception that caused this error
      requestUri - The URI of the request that failed
      requestBody - The body of the request that failed
    • GraphException

      public GraphException(String code, String message, InputStream inputStream, String requestUri, String requestBody)
      Constructs a GraphException by parsing the error response from Microsoft Graph API.

      This constructor parses the JSON error response to extract detailed error information including error code, message, request ID, timestamp, and any additional error details.

      Parameters:
      code - The HTTP status code or error code
      message - The initial error message
      inputStream - The response stream containing the error details in JSON format
      requestUri - The URI of the request that failed
      requestBody - The body of the request that failed
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Throwable
    • getCode

      public String getCode()
      Gets the error code from the Microsoft Graph API response.
      Returns:
      The error code (e.g., "InvalidAuthenticationToken", "ResourceNotFound")
    • getMessage

      public String getMessage()
      Gets the detailed error message.
      Overrides:
      getMessage in class Throwable
      Returns:
      The human-readable error message
    • getRequestId

      public String getRequestId()
      Gets the unique request identifier for troubleshooting.

      This ID can be provided to Microsoft support to help diagnose issues.

      Returns:
      The request ID from the Graph API response
    • getDate

      public Date getDate()
      Gets the timestamp when the error occurred.
      Returns:
      The date and time of the error
    • getDetails

      public List<ErrorDetail> getDetails()
      Gets additional error details if available.
      Returns:
      A list of error detail objects containing additional information
    • getTraceId

      public String getTraceId()
      Gets the trace ID for OAuth authentication errors.
      Returns:
      The trace ID from OAuth error responses
    • getCorrelationId

      public String getCorrelationId()
      Gets the correlation ID for OAuth authentication errors.
      Returns:
      The correlation ID from OAuth error responses
    • getErrorUri

      public String getErrorUri()
      Gets the error URI with additional information about the error.
      Returns:
      A URI pointing to error documentation
    • getRequestUri

      public String getRequestUri()
    • getRequestBody

      public String getRequestBody()