REST: Refactor scheme checks and use send_error for error responses.