An action may be maintained, by the person arrested, against the officer or other person making an arrest contrary to the provisions of the last section, in which the plaintiff is entitled to recover treble damages. A similar action may also be maintained, in a like case, by the party in whose behalf the witness was subpoenaed, or the order procured, to recover the damages sustained by him, in consequence of the arrest. But a sheriff, or other officer, or person, is not so liable, unless the person claiming an exemption from arrest, makes, if required by the sheriff or officer, an affidavit, to the effect that he was legally subpoenaed or ordered to attend, and that he was not so subpoenaed or ordered by his own procurement, with the intent of avoiding arrest. In his affidavit he must specify the court or officer, the place of attendance, and the cause in which he was so subpoenaed or ordered. The affidavit may be taken before the officer arresting him, and exonerates the officer from liability for not making the arrest.