Fix bug on order assets that was stopping the flow after paying.

This commit is contained in:
Pedro Gutiérrez 2019-04-11 14:02:03 +02:00
parent c2de39769b
commit 29ea28cf90
2 changed files with 13 additions and 3 deletions

View File

@ -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}`)

View File

@ -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()