Error Handling

For each individual target item being exported, the adapter must report if the attempt resulted in an error that prevented an update. These errors are reported as a list of com.hybris.datahub.dto.item.ErrorData instances and are passed to Data Hub as part of the complete publication step.

At a minimum, capture the canonical item Id that was referenced by the failed target item in the error detail. The error code property can be used to track codified error responses as they relate to your particular system. Following is a code sample that demonstrated how to construct more meaningful errors when the export of a target item fails. The additional information included here ( the canonicalItemId, the myCode, and the message) assists in understanding why a given error was thrown.

import com.hybris.datahub.dto.item.ErrorData;
 
[...]
 
private ErrorData buildPublicationError(final TargetItem targetItem, final MyCustomException e)
{
    final ErrorData errorData = new ErrorData();
    errorData.setCanonicalItemId(targetItem.getCanonicalItem().getId());
    errorData.setCode(e.getMyCode());
    errorData.setMessage(e.getMessage());
    return errorData;
}

What's next?

As stated above, these errorData instances are vital for setting publication statuses on completion of the publication action. Publication Completion is a vital final step in implementing your custom output adapter, and is covered in the next topic.