Class DataApiResponseException

All Implemented Interfaces:
Serializable

public class DataApiResponseException extends DataApiException
Extends DataApiException to specifically address errors encountered during the processing of responses from the Data API. This exception is particularly useful when a command issued to the API is internally divided into multiple sub-operations, each of which might succeed or fail independently. It aggregates detailed information about each sub-operation, including execution times and any errors encountered, facilitating comprehensive error tracking and debugging.

The commandsList attribute of this exception holds a collection of ExecutionInfos objects, each representing the outcome of a sub-operation. This detailed breakdown helps in identifying specific points of failure within a complex command execution sequence, making it easier for developers to diagnose issues and implement more robust error handling and recovery strategies.

Example usage:

 
 try {
     List<Document> longListOfDocuments;
     collection.insertMany(longListOfDocuments);
 } catch (DataApiResponseException e) {
     e.getCommandsList().forEach(executionInfo -> {
         if (executionInfo.hasErrors()) {
             log.error("Error in sub-operation: " + executionInfo.getErrorDetails());
         }
     });
     // Handle the exception or notify the user
 }
 
 
See Also:
  • Constructor Details

    • DataApiResponseException

      public DataApiResponseException(List<ExecutionInfos> cmdList)
      Constructor with list of constructors.
      Parameters:
      cmdList - command execution list
  • Method Details

    • getApiErrors

      public List<ApiError> getApiErrors()
      Flattening errors as a list.
      Returns:
      list of errors
    • getErrorMessage

      public static String getErrorMessage(List<ExecutionInfos> commands)
      Parse the command list to get first error of first command.
      Parameters:
      commands - input command list
      Returns:
      error message from the API
    • getErrorCode

      public static String getErrorCode(List<ExecutionInfos> commands)
      Parse the command list to get first error of first command.
      Parameters:
      commands - input command list
      Returns:
      error code from the API