Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error event if the server responds with an error #6756

Closed
fasenderos opened this issue May 13, 2021 · 3 comments
Closed

Add error event if the server responds with an error #6756

fasenderos opened this issue May 13, 2021 · 3 comments
Assignees

Comments

@fasenderos
Copy link
Contributor

fasenderos commented May 13, 2021

Hi all, for tracking purpouse I need to have an event if the server responds with an error. Something like BIDDER_ERROR, to be used in the adapter with onBidderError. If you think it could be usefull I can make a PR for that. Thanks

@ChrisHuie
Copy link
Collaborator

I think it would be a useful PR or if you think it is better as documentation I can update the docs if you paste in your code.

@ChrisHuie ChrisHuie self-assigned this Aug 2, 2021
@ChrisHuie ChrisHuie changed the title [Question] Add error event if the server responds with an error Add error event if the server responds with an error Aug 2, 2021
@fasenderos
Copy link
Contributor Author

fasenderos commented Sep 2, 2021

Hi @ChrisHuie apologies for the slow reply. I'm not sure this is the best way for firing the error event because I do not have an extensive knowledge of the prebid framework. Anyway these are the modifications I have done:

1) Defined the event "BIDDER_ERROR": "bidderError" in the constants.json file after this line

"BIDDER_DONE": "bidderDone",

2) Trigger bidder's onBidderError handler and emit the BIDDER_ERROR event, in the onFailure function of the bidderFactory:

/ **
* NOTE the original onFailure only accepts the error message and not the error object, even though ajax.js passes them both.
* For tracking purpose we need also the error object
*/
function onFailure(errorMessage, error) {
    onTimelyResponse(spec.code);
    adapterManager.callBidderError(spec.code, error, bidderRequest)
    events.emit(CONSTANTS.EVENTS.BIDDER_ERROR, { error, bidderRequest });
    logError(`Server call for ${spec.code} failed: ${errorMessage} ${error.status}. Continuing without bids.`);
    onResponse();
}

3) Add the callBidderError function at the end of the adapterManager

adapterManager.callBidderError = function(bidder, error, bidderRequest) {
  const param = { error, bidderRequest };
  tryCallBidderMethod(bidder, 'onBidderError', param);
};

With that I was able to listen for the event onBidderError in my adapter.

 /**
   * Track error
   * @param {XMLHttpRequest.error} error
   * @param {BidderRequest} bidderRequest
   */
  onBidderError: function ({ error, bidderRequest }) {
      .... some logic here
  }

If that make sense for you I can make a PR.

@fasenderos
Copy link
Contributor Author

2) Trigger bidder's onBidderError handler and emit the BIDDER_ERROR event, in the onFailure function of the bidderFactory:

adapterManager.callBidderError(spec.code, error, bidderRequest)
events.emit(CONSTANTS.EVENTS.BIDDER_ERROR, { error, bidderRequest });

Here I know that triggering only the onBidderError handler is enough for my purpose, but the event can be consumed by other bidders and analytics pixels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants