The "ErrorHandling" sample extension showcases various error handling features.
Every extension can define its own set of error codes and set additional information about errors in the Command instance.
The error details provided by the extension are returned in the error field of the command response like this:
- The value of the
domainfield specifies which domain returned the error. This is important because every extension can specify its own error codes. - The value of the
codefield corresponds to the value ofCommand.ExtensionResult. - The value of the
messagefield corresponds to the value returned by the extension'sstring ErrorString(uint)method that is called by the HMI server if the extension setsCommand.ExtensionResultto a non-zero value.
First steps:
-
Call the 'FailingFunction' function symbol of the sample extension.
Request:
{ "requestType": "ReadWrite", "commands": [ { "symbol": "ErrorHandling.FailingFunction", "commandOptions": [ "SendWriteValue", "SendErrorMessage" ] } ] }Response:
{ "commands": [ { "symbol": "ErrorHandling.FailingFunction", "error": { "domain": "ErrorHandling", "code": 2, "message": "FUNCTION_FAILED", "reason": "This function symbol always fails." } } ] } -
Call the 'NotImplementedFunction' function symbol of the sample extension.
Request:
{ "requestType": "ReadWrite", "commands": [ { "symbol": "ErrorHandling.NotImplementedFunction", "commandOptions": [ "SendWriteValue", "SendErrorMessage" ] } ] }Response:
{ "commands": [ { "symbol": "ErrorHandling.NotImplementedFunction", "error": { "domain": "ErrorHandling", "code": 1, "message": "INTERNAL_ERROR", "reason": "An exception was thrown while the command was processed by the extension: 'Handler is missing.'." } } ] } -
Call a function that doesn't exist. The HMI server should catch this problem and return an error.
Request:
{ "requestType": "ReadWrite", "commands": [ { "symbol": "ErrorHandling.UnknownFunction", "commandOptions": [ "SendWriteValue", "SendErrorMessage" ] } ] }Response:
{ "commands": [ { "symbol": "ErrorHandling.UnknownFunction", "error": { "domain": "TcHmiSrv", "code": 513, "message": "SYMBOL_NOT_MAPPED", "reason": "Symbol not mapped" } } ] }