Skip to content

Commit

Permalink
returning an error if the mtype is missing or invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaneyama committed Sep 19, 2024
1 parent 7c2044a commit 03c700e
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 7 deletions.
19 changes: 12 additions & 7 deletions adapters/inmobi/inmobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func (a *InMobiAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR

for _, sb := range serverBidResponse.SeatBid {
for i := range sb.Bid {
mediaType := getMediaTypeForImp(sb.Bid[i])
mediaType, err := getMediaTypeForImp(sb.Bid[i])
if err != nil {
return nil, []error{err}
}
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: mediaType,
Expand Down Expand Up @@ -118,17 +121,19 @@ func preprocess(imp *openrtb2.Imp) error {
return nil
}

func getMediaTypeForImp(bid openrtb2.Bid) openrtb_ext.BidType {
func getMediaTypeForImp(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo
return openrtb_ext.BidTypeVideo, nil
case openrtb2.MarkupAudio:
return openrtb_ext.BidTypeAudio
return openrtb_ext.BidTypeAudio, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative
return openrtb_ext.BidTypeNative, nil
default:
return openrtb_ext.BidTypeBanner
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Unsupported mtype %d for bid %s", bid.MType, bid.ID),
}
}
}
97 changes: 97 additions & 0 deletions adapters/inmobi/inmobitest/supplemental/invalid-mtype.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"mockBidRequest": {
"site": {
"page": "https://www.inmobi.com"
},
"id": "req-id",
"device": {
"ip": "1.1.1.1",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
},
"imp": [
{
"ext": {
"bidder": {
"plc": "1621323101291"
}
},
"video": {
"w": 640,
"h": 360,
"mimes": ["video/mp4"]
},
"id": "imp-id"
}
]
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://api.w.inmobi.com/showad/openrtb/bidder/prebid",
"body": {
"site": {
"page": "https://www.inmobi.com"
},
"id": "req-id",
"device": {
"ip": "1.1.1.1",
"ua": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
},
"imp": [
{
"ext": {
"bidder": {
"plc": "1621323101291"
}
},
"video": {
"w": 640,
"h": 360,
"mimes": ["video/mp4"]
},
"id": "imp-id"
}
]
},
"impIDs":["imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "req-id",
"seatbid": [
{
"bid": [
{
"ext": {
"prebid": {
"meta": {
"networkName": "inmobi"
}
}
},
"nurl": "https://some.event.url/params",
"crid": "123456789",
"adomain": [],
"price": 2.0,
"id": "1234",
"adm": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <VAST version=\"3.0\"></VAST>",
"impid": "imp-id",
"mtype": 0
}
]
}
]
}
}
}],

"expectedBidResponses":[],
"expectedMakeBidsErrors":[
{
"value":"Unsupported mtype 0 for bid 1234",
"comparison":"literal"
}
]
}


0 comments on commit 03c700e

Please sign in to comment.