divides out error and controller handling to their own functions to make it easier to override with custom behavior