diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index 7946bd8..a78e140 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -136,9 +136,17 @@ export class Brizo extends Instantiable { const response = await WebServiceConnectorProvider .getConnector() .get(url) - const filename = response.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1] - if (destination) { + if (!response.ok) { + throw new Error("Response error.") + } + let filename + try { + filename = response.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1] + } catch { + throw new Error("Response is not containing file name.") + } + if (destination) { await new Promise(async (resolve, reject) => { fs.mkdirSync(destination, {recursive: true}) const fileStream = fs.createWriteStream(`${destination}${filename}`) diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 203797d..05a07bc 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -227,6 +227,8 @@ export class OceanAssets extends Instantiable { this.logger.log("Locking payment") + const accessGranted = accessCondition.getConditionFulfilledEvent(agreementId).once() + const paid = await oceanAgreements.conditions.lockReward(agreementId, metadata.base.price, consumer) if (paid) { @@ -238,7 +240,7 @@ export class OceanAssets extends Instantiable { reject("Error on payment") } - await accessCondition.getConditionFulfilledEvent(agreementId).once() + await accessGranted this.logger.log("Access granted") resolve()