Skip to content

Commit

Permalink
fix: check if callback is a function (#54)
Browse files Browse the repository at this point in the history
* fix: check if callback is a function

* refactor: add more check points for callback

Co-authored-by: Pablo Rey Sobral <pablo.rey@adevinta.com>
  • Loading branch information
paulusrex and Pablo Rey Sobral committed Dec 14, 2020
1 parent b7cb511 commit dcbabe0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/main/application/TcfApiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class TcfApiV2 {
}

getTCData(callback, vendorIds) {
callback(this._getTCDataUseCase.execute({vendorIds}), true)
typeof callback === 'function' &&
callback(this._getTCDataUseCase.execute({vendorIds}), true)
}

ping(callback) {
callback(this._pingUseCase.execute(), true)
typeof callback === 'function' &&
callback(this._pingUseCase.execute(), true)
}

addEventListener(callback) {
Expand All @@ -51,10 +53,13 @@ class TcfApiV2 {
getVendorList(callback, vendorListVersion) {
return this._getVendorListUseCase
.execute({vendorListVersion})
.then(vendorList => callback(vendorList, true))
.then(
vendorList =>
typeof callback === 'function' && callback(vendorList, true)
)
.catch(error => {
console.log('Error obtaining the vendor list', error)
callback(null, false)
typeof callback === 'function' && callback(null, false)
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/domain/service/EventStatusService.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ export class EventStatusService {
observer: callback
})
} catch (error) {
callback(null, false)
typeof callback === 'function' && callback(null, false)
return
}

const tcData = this._getTCDataUseCase.execute()
tcData.listenerId = reference

callback(tcData, true)
typeof callback === 'function' && callback(tcData, true)
}

removeEventListener({callback, listenerId}) {
const success = this._domainEventBus.unregister({
eventName: EVENT_STATUS,
reference: listenerId
})
callback(success)
typeof callback === 'function' && callback(success)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/infrastructure/controller/TcfApiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TcfApiController {

_reject(callback) {
try {
callback(null, false)
typeof callback === 'function' && callback(null, false)
} catch (ignored) {}
}

Expand Down

0 comments on commit dcbabe0

Please sign in to comment.