Updated error handling for the cancel operation.