I feel like there must be some way to refactor this to share with the error handler but I can't think of anything