Moved callback related error processing into a single helper function