Accessing resource block error when called from javascript block

If I were using a resource block, with “continue on error”, and an error occurred, I would have some error information available in a downstream javascript block. How can I get that same error information, when using a single-step resource function, called from javascript?

If wired up as above,

callGetCaseWrapper.error will be

{
  error: 'Error: \n' +"WHERE Id = 'abc123'\n" +'      ^\n' +'ERROR at Row:3:Column:7\n' +'invalid ID field: abc123 (line 1)',
  data: null,
  value: null,
  metadata: null,
  loggingMetadata: undefined
}

if callGetCaseWrapper is wired up directly to getCase, code1 will log the full error object I would expected

callGetCaseWrapper.error will be

{
  statusCode: 400,
  error: 'Bad Request',
  message: '\n' +"WHERE Id = 'abc123'\n" +'      ^\n' +'ERROR at Row:3:Column:7\n' +'invalid ID field: abc123',
  data: null
}

To be explicit, I am asking for 2 things here.

  1. callGetCaseWrapper calls getCaseWrapper which in turn calls getCaseWrapper. As the screenshot above shows, there is no try/catch around the call to getCase. Therefore, the exception that is effectively raised by getCase should be passed through, and not mangled with.
  2. If I were to modify getCaseWrapper and wrap getCase in a try/catch, when an error occurs, I would like to gain access to the same error as if getCase were called outside of javascript.

And then, a big :cherries: on top – it would be outstanding if I could establish the shape of the error object from a javascript block. Example below.

const myError = new Error("Something is messed up.");
myError.statusCode: 422;
myError.error = 'You provided an invalid value for xyz';
myError.message = 'blah';
raise myError;