How to get the code from BpnmError in history data

I have a process that can be ended because of multiple reasons.

To terminate the process I either:

  • use the error end event in the BPMN process model where i can specify an error code
  • throw a BpmnError exception in a service task delegate

Those errors are never catched because I want to terminate the process.
However I can’t figure out how to get the error code starting from a HistoricProcessInstance.