isCancelled static method

bool isCancelled(
  1. Object error
)

Check if an error indicates the operation was cancelled

Returns true if the error is a CancelledError or a DioException with type cancel.

Example:

try {
  await provider.chat(messages, cancelToken: token);
} catch (e) {
  if (CancellationHelper.isCancelled(e)) {
    print('Operation cancelled');
  }
}

Implementation

static bool isCancelled(Object error) {
  // Check for our custom CancelledError
  if (error is CancelledError) return true;

  // Check for Dio's raw cancellation exception
  // (this should not normally occur as we map it to CancelledError)
  return error is DioException && CancelToken.isCancel(error);
}