GSMA-CPAS / BWRP-chaincode

Apache License 2.0
1 stars 0 forks source link

Implement custom & consistent error handling in go and node #12

Closed sschulz-t closed 3 years ago

sschulz-t commented 3 years ago

This PR adds a custom error handling for go chaincode and nodejs client code. The Chaincode will return a custom error formatted as json (e.g. { "code": "ERROR_DOCUMENT_ID_EXISTS", "message": "failed to ..."}).

The basic idea is to log all errors in full detail to the chaincode logfile and return a summary and an error code. On the Blockchainadapter we can then this message and forward the error code together with a filtered/new detail message (e.g. filter out security related stuff).

The error codes are defined in chaincode/hybrid/errorcode/errors.go (ERROR_NON_LOCAL_ACCESS_DENIED, ERROR_OFFCHAIN_DB_CONFIG, ERROR_INTERNAL, ...)

There will be a second PR for the blockchain adapter that implements the error handling on the client written in nodejs.

sgerhardt-trilobyte commented 3 years ago

If I understand the code correctly, the error code "ERROR_CERT_INVALID" will be returned if the "cansigndocument" attribute value is not "yes". However, a certificate can be valid but not contain the "cansigndocument" attribute value "yes". Wouldn't a separate error code be useful here like "ERROR_SIGN_NO_PERMISSION" or similar? Makes the error handling easier for the UI/Client later. if errorCode == 'ERROR_SIGN_NO_PERMISSION' -> user has no permission to sign this document

sgerhardt-trilobyte commented 3 years ago

sorry ... "CanSignDocument" not "cansigndocument"