A surety or indorser shall not suffer judgment or a decree to be rendered against him by confession or default, without the consent of the principal debtor. And a surety or indorser who shall be sued alone, shall give notice of the suit to the principal debtor, if resident in this state, and if he have knowledge or information of any defense to the action which the principal debtor has, he shall make such defense; and if a surety or indorser, when sued alone, fail to give such notice to the principal debtor, in case he be a resident of this state, or to make such defense in the action of which he has knowledge or information, he shall be barred of all recovery against the principal debtor in case the principal debtor have at the time a good defense to the action of the creditor.