refactor(server): pull out error handler and helpers