middleware for custom error pages