Skip to content

Commit

Permalink
Adding error check and making sure that priceType can be optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-lundin committed Sep 12, 2023
1 parent a7ce04f commit e847ee1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
24 changes: 19 additions & 5 deletions adapters/adnuntius/adnuntius.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
Message: fmt.Sprintf("ignoring imp id=%s, Adnuntius supports only Banner", imp.ID),
}}
}

var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, []error{&errortypes.BadInput{
Expand All @@ -210,7 +211,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
var adnuntiusExt openrtb_ext.ImpExtAdnunitus
if err := json.Unmarshal(bidderExt.Bidder, &adnuntiusExt); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error unmarshalling ExtImpBmtm: %s", err.Error()),
Message: fmt.Sprintf("Error unmarshalling ExtImpValues: %s", err.Error()),
}}
}

Expand Down Expand Up @@ -351,13 +352,26 @@ func generateAdResponse(ad Ad, imp openrtb2.Imp, html string, request *openrtb2.
}

price := ad.Bid.Amount
priceType, _, _, _ := jsonparser.Get(imp.Ext, "bidder", "priceType")

if string(priceType) != "" {
if strings.ToLower(string(priceType)) == "net" {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error unmarshalling ExtImpBidder: %s", err.Error()),
}}
}

var adnuntiusExt openrtb_ext.ImpExtAdnunitus
if err := json.Unmarshal(bidderExt.Bidder, &adnuntiusExt); err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error unmarshalling ExtImpValues: %s", err.Error()),
}}
}

if adnuntiusExt.PriceType != "" {
if strings.EqualFold(string(adnuntiusExt.PriceType), "net") {
price = ad.NetBid.Amount
}
if strings.ToLower(string(priceType)) == "gross" {
if strings.EqualFold(string(adnuntiusExt.PriceType), "gross") {
price = ad.GrossBid.Amount
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"mockBidRequest": {
"id": "test-request-id",
"user": {
"id": "1kjh3429kjh295jkl"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"auId": "123",
"priceType": 123
}
}
}
]
},
"httpCalls": [],
"expectedMakeRequestsErrors": [
{
"value": "Error unmarshalling ExtImpValues: json: cannot unmarshal number into Go struct field ImpExtAdnunitus.priceType of type string",
"comparison": "literal"
}
]
}

0 comments on commit e847ee1

Please sign in to comment.