def set_response_header(response, request, error_code=header_pb2.CommonError.CODE_OK, error_message=None): """Sets the ResponseHeader header in the response.""" header = header_pb2.ResponseHeader() header.request_received_timestamp = bosdyn.util.now_timestamp() header.request_header.CopyFrom(request.header) header.error.code = error_code if error_message: header.error.message = error_message response.header.CopyFrom(header)
def add_common_header(response, request, error_code=HeaderProto.CommonError.CODE_OK, error_message=None): """Sets the common header on the response. Args: response: The response object to fill the header with. request: The request to be echoed in the response common header. error_code: The code to use, OK by default. error_message: Any error message to include, empty by default. """ header = HeaderProto.ResponseHeader() header.request_header.CopyFrom(request.header) header.error.code = error_code if error_message: header.error.message = error_message response.header.CopyFrom(header)
def populate_response_header(response, request, error_code=header_pb2.CommonError.CODE_OK, error_msg=None): """Sets the ResponseHeader header in the response. Args: response (bosdyn.api Response message): The GRPC response message to be populated. request (bosdyn.api Request message): The header from the request is added to the response. error_code (header_pb2.CommonError): The status for the RPC response. error_msg (str): An optional error message describing a bad header status failure. Returns: Mutates the response message's header to be fully populated. """ header = header_pb2.ResponseHeader() header.request_received_timestamp.CopyFrom(bosdyn.util.now_timestamp()) header.request_header.CopyFrom(request.header) header.error.code = error_code if error_msg: header.error.message = error_msg copied_request = copy.copy(request) strip_large_bytes_fields(copied_request) header.request.Pack(copied_request) response.header.CopyFrom(header)