Skip to content

Commit

Permalink
fix: normalize promise now have the ability to treat errors properly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yagovelazquezfreestar authored Sep 11, 2024
1 parent 6cbdba1 commit 81e7114
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,19 @@ export function attachIdSystem(submodule) {
}
}

function normalizePromise(fn) {
function normalizePromise(fn, handleErrors = false, fnName) {
// for public methods that return promises, make sure we return a "normal" one - to avoid
// exposing confusing stack traces
return function() {
return Promise.resolve(fn.apply(this, arguments));
const promise = Promise.resolve(fn.apply(this, arguments));

if (handleErrors) {
return promise.catch(error => {
logWarn(`Error occurred in ${fnName}: ${error.message || error}`);
});
}

return promise;
}
}

Expand Down Expand Up @@ -1088,7 +1096,7 @@ export function init(config, {delay = GreedyPromise.timeout} = {}) {
(getGlobal()).getUserIdsAsEids = getUserIdsAsEids;
(getGlobal()).getEncryptedEidsForSource = normalizePromise(getEncryptedEidsForSource);
(getGlobal()).registerSignalSources = registerSignalSources;
(getGlobal()).refreshUserIds = normalizePromise(refreshUserIds);
(getGlobal()).refreshUserIds = normalizePromise(refreshUserIds, true, 'refreshUserIds');
(getGlobal()).getUserIdsAsync = normalizePromise(getUserIdsAsync);
(getGlobal()).getUserIdsAsEidBySource = getUserIdsAsEidBySource;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prebid.js",
"version": "8.49.8",
"version": "8.49.81",
"description": "Header Bidding Management Library",
"main": "src/prebid.js",
"scripts": {
Expand Down

0 comments on commit 81e7114

Please sign in to comment.