From d10743413b8440264d0021a0bbb3d41ded9c3b21 Mon Sep 17 00:00:00 2001 From: Mentor Palokaj Date: Wed, 8 Dec 2021 10:21:40 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20draft=20update=20by=20address=20cha?= =?UTF-8?q?nging=20room?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/nft-media/changing-room.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/functions/nft-media/changing-room.js b/functions/nft-media/changing-room.js index a650256..e6767de 100644 --- a/functions/nft-media/changing-room.js +++ b/functions/nft-media/changing-room.js @@ -85,9 +85,27 @@ async function generateNewOutfitFromId( id, network='mainnet' ) { // Generate, compile and upload image // Path format of new rocketeers is id-outfitnumber.{svg,jpg} - const newOutfitSvg = await svgFromAttributes( rocketeer.attributes, `${ network }Rocketeers/${ id }-${ available_outfits + 1 }` ) + try { - return newOutfitSvg + const newOutfitSvg = await svgFromAttributes( rocketeer.attributes, `${ network }Rocketeers/${ id }-${ available_outfits + 1 }` ) + + return newOutfitSvg + + } catch( e ) { + + // If the svg generation failed, reset the attributes to their previous value + await db.collection( `${ network }Rocketeers` ).doc( id ).set( { + attributes: [ + ...staticAttributes, + { trait_type: 'available outfits', value: available_outfits, }, + { trait_type: 'last outfit change', value: last_outfit_change, display_type: "date" } + ] + } ,{ merge: true } ) + + // Propagate error + throw e + + } }