Catch 404 in middleware