There is one root card and one other card on the stack. I'm doing data validation. If there is no file value selected in the drop-down box, this is the error handler to create a new error card. The originating function throws an error and the catch calls my error handler. When the error is triggered, it does nothing, but log the error message. It seems to create the new card in the execution transcript, the header, and section, however, it doesn't show. I don't see an error in the execution transcript. Everything succeeds, but there is no new card.
function error(e){
try{
// create new card, header, and section
var header = CardService.newCardHeader().setTitle('Error')
.setImageUrl('http://www.pvhc.net/img55/waclmgwigxuizcqbxjdx.jpg')
.setImageStyle(CardService.ImageStyle.SQUARE);
var section = CardService.newCardSection()
.setHeader('<b>Error Message:</b>')
.addWidget(CardService.newTextParagraph().setText(e));
var card = CardService.newCardBuilder()
.setHeader(header).addSection(section).build();
// Create Nav object
var nav = CardService.newNavigation().pushCard(card);
// Check if my function is being called and the error message is correct.
Logger.log(e);
// push card onto stack.
return CardService.newActionResponseBuilder().setNavigation(nav);
}catch(e){Logger.log(e.message);}
}
Update: In my catch statement, I didn't have a return statement before calling the error function. Now I'm getting a run time error: 'Missing required fields in markup: '. Not sure why.
Although I originally didn't include the 'return' when calling my error handler, also, I didn't build the action response builder when returning it.
Original statement: return CardService.newActionResponseBuilder().setNavigation(nav);
Correction: return CardService.newActionResponseBuilder().setNavigation(nav).build();
This now works.