This should be within the `finish()` function to handle both success and error states.