You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a private data collection with only two organizations (lets say Org1 and Org2) in its policy defined in the collections_config.json file.
The transaction function is written in a way that it will send out both the public and the associated private data based on which Org the calling peer belongs to. I am using a simple try/catch block to catch an exception while retrieving private data to decide whether to include or exclude the private data.
try {
byte[] privateData = context.getStub().getPrivateData(collectionName, key);
// format and include in the response
} catch (Exceptione) {
// failed, possibly not authorized to access private data// don't include in the response
}
This works fine, as an attempt to access private data by any other member of an organization (say Org3) which is not part of the collection configuration, will throw an exception. However, it always throws a RuntimeException - makes it impossible to differentiate whether it is really an endorsement error or or something else went wrong with the chaincode invocation.
My question: Is there a "cleaner" way other than a try/catch using which I can assert if the invoking peer can access the private data collection?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a private data collection with only two organizations (lets say Org1 and Org2) in its policy defined in the
collections_config.json
file.The transaction function is written in a way that it will send out both the public and the associated private data based on which Org the calling peer belongs to. I am using a simple try/catch block to catch an exception while retrieving private data to decide whether to include or exclude the private data.
This works fine, as an attempt to access private data by any other member of an organization (say Org3) which is not part of the collection configuration, will throw an exception. However, it always throws a
RuntimeException
- makes it impossible to differentiate whether it is really an endorsement error or or something else went wrong with the chaincode invocation.My question: Is there a "cleaner" way other than a try/catch using which I can assert if the invoking peer can access the private data collection?
Beta Was this translation helpful? Give feedback.
All reactions